1.本篇内容转发自http://www.cnblogs.com/gaoyuchuanIT/articles/2946314.html
2. 首先在程序中引用: System.Diagnostics;
3. 开启进程:
///
/// 开启进程
///
/// 进程路径(如:@"C:WINDOWSsystem32osk.exe")
///
public bool StartProcess(string aProPath)
{
try
{
Process ps = Process.Start(aProPath);//开启进程
}
catch (Exception)
{
return false; //失败
}
return true; //成功
}
4. 停止进程:
///
/// 关闭进程
///
/// 进程名称(不带.exe)
///
public bool CloseProcess(string aName)
{
try
{
Process[] ps = Process.GetProcessesByName(aName);//根据进程名称,获取该进程信息
foreach (Process p in ps)
{
p.Kill();
p.WaitForExit();
p.Close(); //关闭
}
}
catch (Exception ex)
{
return false; //失败
}
return true; //成功
}