一。重新启动指定可执行程序。(如果程序已运行,则先中止,再运行。如果未运行,则运行它) private void RestartApplication(string exeFileName) { if (string.IsNullOrEmpty(exeFileName) || !System.IO.File.Exists(exeFileName)) { return; }
//中止正在运行的进程。 Process[] processes = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(exeFileName)); if ((processes != null) && (processes.Length > 0)) { processes[0].Kill(); }
//启动新进程 Process newProcess = new Process(); newProcess.StartInfo.FileName = exeFileName; newProcess.Start(); }
二。在.net 开发RichClient应用程序中,有时要调用另外一个应用程序,并且在被调用的程序结束后,希望返回执行结果的状态。
下面的代码用appDomain 和 Process 两种技术实现这种应用: