在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//检测系统进程是否启动
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;
}
|
请发表评论