【发布时间】:2011-06-19 18:41:34
【问题描述】:
我有一个用 C++ 编写的 .exe 文件。我用过;
Process.Start("E:\\cmdf.exe");
从 C# 执行代码。
现在我需要:
- 隐藏命令提示符
- 然后想办法停止命令提示符(如关闭应用程序)
我该怎么做?
【问题讨论】:
我有一个用 C++ 编写的 .exe 文件。我用过;
Process.Start("E:\\cmdf.exe");
从 C# 执行代码。
现在我需要:
我该怎么做?
【问题讨论】:
要在没有命令窗口的情况下启动,试试这个:
var exePath = @"E:\cmdf.exe";
var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = exePath;
p.Start();
然后结束进程:
p.Kill();
【讨论】:
添加到其他答案:
还有WindowStyle property,您可以将其设置为WindowStyle.Hidden。
【讨论】:
这是隐藏命令提示符的代码,它对我有用,希望对你也有帮助。
Process p = new Process();
StreamReader sr;
StreamReader se;
StreamWriter sw;
ProcessStartInfo psi = new ProcessStartInfo(@"bar.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.CreateNoWindow = true;
p.StartInfo = psi;
p.Start();
【讨论】: