1

我有一个在 Windows 7 中运行良好的 .net 控制台,但由于某种原因,如果我在 Windows XP 中运行相同的确切代码,我会收到错误消息“没有进程与此对象相关联”,然后它指向prc.WaitForExit();

代码如下:

   string path;

   path = System.IO.Path.GetDirectoryName(
           System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

   Process prc = new Process();  
   prc.StartInfo.FileName = path + "\\Process2.bat";
   prc.Start();

   prc.WaitForExit();
   System.Threading.Thread.Sleep(10);
   Console.WriteLine("{0} Task Process2 completed with process ID {1} and return code {2}. ", DateTime.Now.ToString(), prc.Id, prc.ExitCode.ToString());

   System.IO.StreamWriter file =
      new System.IO.StreamWriter(logpath + "\\logfile.txt", true);
        file.WriteLine(DateTime.Now.ToString() + " Task Process2 completed with process ID " + prc.Id + " and return code " + prc.ExitCode.ToString());

  file.Close();

请帮忙。非常感谢任何帮助。

4

0 回答 0