//检测系统进程是否启动
public virtual bool CheckProcess(string processName)
{
Process[] p = Process.GetProcessesByName(processName);
bool isOK = false;
if (p != null)
{
if (p.Length > 0)
{
isOK = true;
}
}
return isOK;
}
///启动进程
public virtual bool StartProcess(string ProcessPath,string ProcessName)
{
bool ret = false;
Process p = new Process();
string proc = Path.Combine(ProcessPath,ProcessName);
ProcessStartInfo psi = new ProcessStartInfo(proc);
psi.UseShellExecute = false;
p.StartInfo = psi;
p.Start();
Thread.Sleep(2000);
if (CheckProcess(ProcessName))
ret = true;
return ret;
}
//杀掉进程
public virtual bool KillProcess(string processName)
{
bool flag = false;
try
{
foreach (System.Diagnostics.Process process in System.Diagnostics.Process.GetProcessesByName(processName))
{
process.Kill();
}
flag = true;
}
catch (Exception ex)
{
flag = false;
}
return flag;
}