test.exe为测试进程,需查看是否已运行该进程,如果已运行该进程则将该进程程序前端显示;
如果该进程没有开启,则开启该进程
Process[] processCurrent = Process.GetProcesses();//获取进程列表
for (int i = 0; i < processCurrent.Length; i++)
{
if (processCurrent[i].ProcessName == "test")//test为进程名
{
ShowWindow(processCurrent[i].MainWindowHandle, 1);
SetForegroundWindow(processCurrent[i].MainWindowHandle);
return;
}
}
Process process = new Process();
process.StartInfo.FileName =testPath+"\\"+"test.exe";
process.StartInfo.LoadUserProfile = true;
process.StartInfo.WorkingDirectory = testPath;
process.Start();
评论