/// <summary>
/// 系统进程操作
/// </summary>
public class GSProcess
{
public GSProcess() { }
/// <summary>
/// 获取操作系统进程列表
/// </summary>
public Dictionary<string, string> GetAllProcess()
{
Process[] ps = Process.GetProcesses();
Dictionary<string, string> di = new Dictionary<string, string>();
int i = 0;
StringBuilder sb = new StringBuilder();
foreach (Process p in ps)
{
if (p.MainWindowHandle != null)
{
di.Add(p.Id.ToString(), p.ProcessName);
sb.Append("ID: " + p.Id.ToString() + " ProcessName " + p.ProcessName);
}
}
return di;
}
/// <summary>
/// 是否存在某种进程
/// </summary>
/// <param name="processname"></param>
/// <returns></returns>
public bool isExist(string processname)
{
Dictionary<string, string> di = new Dictionary<string, string>();
di = GetAllProcess();
return di.ContainsValue(processname);
}
/// <summary>
/// 杀进程
/// </summary>
/// <param name="processname"></param>
public void Kill(string processname)
{
Process[] ps = Process.GetProcesses();
foreach (Process p in ps)
{
if (p.MainWindowHandle != null && p.ProcessName.Equals(processname))
{
p.Kill();
}
}
}
}