这段代码演示了如何根据进程名关闭进程和启动进程
代码语言:javascript复制private bool CloseProcess(string CloseProcessName)
{
try
{
//根据进程名称,获取该进程信息
Process[] MyProcessS = Process.GetProcessesByName(CloseProcessName);
foreach (Process MyProcess in MyProcessS)
{
MyProcess.Kill();
MyProcess.WaitForExit();
MyProcess.Close();
Thread.Sleep(10000);
}
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// 创建进程
/// </summary>
public bool StartProcess(string StartProPath)
{
try
{
Process TheStartProcess = Process.Start(StartProPath);
}
catch (Exception)
{
return false;
}
return true;
}</pre>