1

下面的代码工作正常,但我需要添加 WaitForExit 方法。但它没有显示为可用。我错过了什么?谢谢。

ProcessStartInfo process = new ProcessStartInfo("cmd.exe", @"/C " + AppDomain.CurrentDomain.BaseDirectory + "Setupws.exe");
process.Verb = "runas";
process.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(process);
4

2 回答 2

5

WaitForExit()是一个实例方法,它要求您创建一个实例Process并运行它,而不是使用静态Process.Start()而不捕获 Process 返回值。

创建Process实例并设置实例ProcessStartInfo后,调用它的Start()实例方法,然后调用WaitForExit()实例。

ProcessStartInfo info = new ProcessStartInfo();
//Set info properties...
Process process = new Process();
process.StartInfo = info;
//set other process properties...
process.Start();
process.WaitForExit();
于 2012-12-07T16:05:51.107 回答
4

尝试:

    ProcessStartInfo process = new ProcessStartInfo("cmd.exe", @"/C " +          AppDomain.CurrentDomain.BaseDirectory + "Setupws.exe");
    process.Verb = "runas";
    process.WindowStyle = ProcessWindowStyle.Hidden;
    Process p = Process.Start(process);
    p.WaitForExit();
于 2012-12-07T16:06:41.940 回答