开发者

C# hide, background, processinfo

开发者 https://www.devze.com 2023-03-16 06:10 出处:网络
I have th开发者_高级运维is code: ProcessStartInfo PSI = new ProcessStartInfo(\"cmd.exe\"); PSI.CreateNoWindow = true;

I have th开发者_高级运维is code:

ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
PSI.CreateNoWindow = true;
PSI.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = true;
Process p = Process.Start(PSI);

problem is, when I build it, the command prompt still appears. How can I hide it?Thanks!


In Visual Studio, change the output type under Application in the project properties to Windows Application.

Project Properties > Application > Output Type: "Windows Application"

Also try:

PSI.UseShellExecute = false;


After copy pasting your code, there's an exception that you probably aren't noticing. To redirect the IO streams, the UseShellExecute property must be set to false.

Also, PSI.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; is not required. Here is your working code:

ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
PSI.CreateNoWindow = true;
//PSI.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
Process p = Process.Start(PSI);
0

精彩评论

暂无评论...
验证码 换一张
取 消