Search code examples
c#vb.netprocessparent-child

Start new process, without being a child of the spawning process


How would I go about starting a new process without it being the child of the calling process.

Example:

Main Program (Caller.exe)

process.start("file.exe")

Image:

enter image description here


Solution

  • Here is the code that I'm now using. I thought that it may be useful to someone. It accepts one argument. The argument is a base64 encoded string that decodes to the path of the file that you would like to run.

     Module Module1
    
        Sub Main()
            Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
            If CommandLineArgs.Count = 1 Then
                Try
                    Dim path As String = FromBase64(CommandLineArgs(0))
                    Diagnostics.Process.Start(path)
                Catch
                End Try
                End
            End If
        End Sub
    
        Function FromBase64(ByVal base64 As String) As String
            Dim b As Byte() = Convert.FromBase64String(base64)
            Return System.Text.Encoding.UTF8.GetString(b)
        End Function
    
    End Module