1 public void CheckProcess() 2 { 3 System.Diagnostics.Process[] processList = System.Diagnostics.Process.GetProcesses(); 4 bool IFExit = false; 5 string path="xxx";\\xxx作为进程的绝对路径 6 foreach (System.Diagnostics.Process process in processList) 7 { 8 if (process.ProcessName=="WindowsFormsApplication4") 9 { 10 IFExit = true; 11 break; 12 } 13 } 14 if (!IFExit) 15 { 16 Process.Start(path); 17 } 18 }
使用相对路径更加灵活.