1. This content is forwarded from http://www.cnblogs.com/gaoyuchuanIT/articles/2946314.html
2. First quoted in the program: System.Diagnostics;
3. Open the process:
<summary>
Open process
</summary>
<param name= "Apropath" > Process path (for example: @ "C:\WINDOWS\system32\osk.exe") </param>
<returns> on Success (true) or failed (false) </returns>
public bool StartProcess (string Apropath)
{
Try
{
Process PS = Process.Start (apropath);//Open Progress
}
catch (Exception)
{
return false; Failed
}
return true; Success
}
4. Stop the process:
<summary>
Close process
</summary>
<param name= "AName" > Process name (without. exe) </param>
<returns> shutdown succeeded (true) or failed (false) </returns>
public bool Closeprocess (string aName)
{
Try
{
Process[] PS = Process.getprocessesbyname (aName);//Gets the process information based on the process name
foreach (Process p in PS)
{
P.kill ();
p.WaitForExit ();
P.close (); Shut down
}
}
catch (Exception ex)
{
return false; Failed
}
return true; Success
}
C # Open and stop processes