我正在使用简单的 C# 静态方法来启动 Windows 应用程序。除了 iexplore.exe 之外,所有 32 位或 64 位应用程序都可以正常工作。
当我打电话时:
ExecHttp(@"C:\Program Files (x86)\Internet Explorer\iexplore.exe", "http://www.google.it");
System.Diagnostics.Process WaitForExit() 方法不等待 iexplore.exe 关闭并且 ExitCode 返回 exitcode=1。
这是 ExecHttp:
public static int ExecHttp(String strURL, String strArguments)
{
int intExitCode = 99;
try
{
Process objProcess = new System.Diagnostics.Process();
strArguments = "-nomerge " + strArguments;
System.Diagnostics.ProcessStartInfo psi = new ProcessStartInfo(strURL, strArguments);
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
psi.UseShellExecute = true;
objProcess.StartInfo = psi;
objProcess.Start();
Thread.Sleep(2000);
objProcess.WaitForExit();
intExitCode = objProcess.ExitCode;
objProcess.Close();
}
catch (Exception ex)
{
//log the exception
throw;
}
return intExitCode;
}
我做了很多搜索,唯一的解决方法是在 System.Diagnostic.Process.ProcessStartInfo Arguments 属性上添加 -nomerge 关键字。WaitForExit() 在其他 Windows .exe 进程上工作正常,但不适用于 iexplore.exe 进程。我们如何测试 iexplore.exe 进程的进程状态?
谢谢