一、加入命名空間
using System.Diagnostics;
二、啟動進程
//Dir所在路徑
private void StartPress(string Dir)
{
Process.Start(Dir);
}
二、關閉過程
private void KillPress(string ProName)
{
ProName = ProName.ToLower();
System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process myProcess in myProcesses)
{
if (ProName == myProcess.ProcessName.ToLower())
myProcess.Kill();
}
}
三、取得當前進程所在路徑
private string GetProcessDir(string ProName)
{
ProName = ProName.ToLower();
Process[] processes = Process.GetProcesses();
string tmp = "";
foreach (Process pro in processes)
{
if (pro.ProcessName.ToLower() == ProName)
tmp = pro.MainModule.FileName;//完整運行路徑
}
return tmp;
}