-1

Windows アプリケーションを起動するために、単純な C# 静的メソッドを使用しています。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 プロセスのプロセス ステータスをテストするにはどうすればよいでしょうか。

ありがとうございました

4

1 に答える 1

0

最後に、このソリューションを実装しました。満足していませんが、機能しています。-nomerge 引数を指定して新しい uri を開いた後、3 秒間待機し、最後にこの新しいページを所有する新しいプロセスを検索します。ここで、期待どおりに機能する WaitForExit() を呼び出します。これが私のコードです。提案は大歓迎です。

public static int ExecHttp(String strBrowserApp, String strURL, String strSessionName, ref String strMessage)
{
int intExitCode = 99;
try
{
     strMessage = String.Empty;
     System.Diagnostics.Process.Start(strBrowserApp, "-nomerge " + (String.IsNullOrEmpty(strURL) ? "" : strURL));
     System.Threading.Thread.Sleep(3000);
     System.Diagnostics.Process objProcess = null;
     System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcesses();
     foreach (System.Diagnostics.Process proc in procs.OrderBy(fn => fn.ProcessName))
     {
          if (!String.IsNullOrEmpty(proc.MainWindowTitle) && proc.MainWindowTitle.StartsWith(strSessionName))
          {
               objProcess = proc;
               break;
          }
      }
      if (objProcess != null)
      {
          objProcess.WaitForExit();
          intExitCode = 0;
          objProcess.Close();
      }
}
catch (Exception ex)
{
     strMessage = ex.Message;
}
}
于 2018-08-11T14:47:58.817 に答える