Skip to main content
 首页 » 编程设计

c#之从 C# 代码启动时隐藏 cmd.exe 窗口

2024年02月20日13tintown

我正在 winforms 应用程序中运行 cmd.exe 进程。但是我似乎无法让控制台窗口在后台运行(即不显示在屏幕上)

这是我的代码

ProcessStartInfo si = new ProcessStartInfo("cmd.exe"); 
si.RedirectStandardInput = true; 
si.RedirectStandardOutput = true; 
si.UseShellExecute = false; 
si.Arguments = "/c"; 
si.WindowStyle = ProcessWindowStyle.Hidden; 
Process p = Process.Start(si);  

请您参考如下方法:

将 CreateNoWindow 设置为 true。

si.CreateNoWindow = true;