[C#] 判斷程式(進程)是否已執行與開啟程式(進程)
以下程式碼是當偵測到目標程式已執行就將它關閉Process[] processCurrent = Process.GetProcesses();for (int i = 0; i < processCurrent.Length; i++)
{
if (processCurrent.ProcessName == "TargetProcess") // TargetProcess 是目標程式名稱
{
ShowWindow(processCurrent.MainWindowHandle, 1);
SetForegroundWindow(processCurrent.MainWindowHandle);
return;
}
}以下程式碼就是將目標程式開啟,假設 TargetProcess.exe 放在同一個目錄下Process process = new Process();
process.StartInfo.FileName =Directory.GetCurrentDirectory() + @"\TargetProcess.exe";
process.StartInfo.LoadUserProfile = true;
process.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
process.Start();
頁:
[1]