And*_*sch 24 c# vb.net process parent-child
如果不是调用进程的子进程,我将如何开始新进程.
例:
主程序(Caller.exe)
process.start("file.exe")
Run Code Online (Sandbox Code Playgroud)
图片:
Jos*_*osh 20
如果产生进程(父)在产生的进程(子进程)之前结束,则父子链断开.要使用它,你必须使用如下的中间存根过程:
Caller.exe→Stub.exe→File.exe.
这里Stub.exe是一个简单的启动程序,它在启动File.exe后结束.
Bli*_*ter 17
我一直在尝试启动一个更新程序进程,该进程删除调用进程的文件并用新文件替换它们。通过设置UseShellExecute = true,我能够在调用进程退出时避免生成的进程退出。
这是使用 WPF 的 .Net Core 3.0 应用程序内部。
var startInfo = new ProcessStartInfo("Updater.exe");
startInfo.UseShellExecute = true;
Process.Start(startInfo);
Environment.Exit(0);
Run Code Online (Sandbox Code Playgroud)
ken*_*n2k 10
如果你开始一个过程,那么你将成为它的父母.
也许您可以尝试从cmd.exe启动进程,因此cmd.exe将成为父进程.
Process proc = Process.Start(new ProcessStartInfo { Arguments = "/C explorer", FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden });
Run Code Online (Sandbox Code Playgroud)
小智 8
这将在没有父级的情况下运行新进程:
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"cmd";
psi.Arguments = "/C start notepad.exe";
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(psi);
Run Code Online (Sandbox Code Playgroud)
And*_*sch -1
这是我现在使用的代码。我认为这可能对某人有用。它接受一个参数。参数是一个 base64 编码的字符串,可解码为您要运行的文件的路径。
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
Run Code Online (Sandbox Code Playgroud)