Gab*_*bor 62 .net c# process processstartinfo
当我开始一个新的过程时,如果我使用它会有什么不同
WindowStyle = Hidden
Run Code Online (Sandbox Code Playgroud)
或者
CreateNoWindow = true
Run Code Online (Sandbox Code Playgroud)
ProcessStartInfo班级的财产?
Liz*_*Liz 76
正如汉斯所说,WindowStyle是一个传递给流程的推荐,应用程序可以选择忽略它.
CreateNoWindow控制控制台如何为子进程工作,但它不能单独工作.
CreateNoWindow与UseShellExecute一起使用,如下所示:
在没有任何窗口的情况下运行该过程
ProcessStartInfo info = new ProcessStartInfo(fileName, arg);
info.CreateNoWindow = true;
info.UseShellExecute = false;
Process processChild = Process.Start(info);
Run Code Online (Sandbox Code Playgroud)
在其自己的窗口中运行子进程(新控制台)
ProcessStartInfo info = new ProcessStartInfo(fileName, arg);
info.UseShellExecute = true; // which is the default value.
Process processChild = Process.Start(info); // separate window
Run Code Online (Sandbox Code Playgroud)
在父级控制台窗口中运行子进程
ProcessStartInfo info = new ProcessStartInfo(fileName, arg);
info.UseShellExecute = false; // causes consoles to share window
Process processChild = Process.Start(info);
Run Code Online (Sandbox Code Playgroud)
Han*_*ant 17
CreateNoWindow仅适用于控制台模式应用程序,它不会创建控制台窗口.
WindowStyle仅适用于本机Windows GUI应用程序.它是一个提示传递给这样一个程序的WinMain()入口点.第四个参数,nCmdShow,告诉它如何显示其主窗口.这是在桌面快捷方式中显示为"运行"设置的相同提示.请注意,"隐藏"不是那里的选项,很少有正确设计的Windows程序尊重该请求.由于这会扼杀用户,他无法再激活程序,只能使用任务管理器将其终止.
SwD*_*n81 13
使用反射器,它看起来像WindowStyle如果使用UseShellExecute设置,否则使用CreateNoWindow.
在MSDN的示例中,您可以看到它们如何设置它:
// Using CreateNoWindow requires UseShellExecute to be false
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
Run Code Online (Sandbox Code Playgroud)
在另一个例子中,它正好在下面,因为UseShellExecute默认为true
// UseShellExecute defaults to true, so use the WindowStyle
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Run Code Online (Sandbox Code Playgroud)