判断进程状态

根据进程名称判断进程是否启动:

//根据名称获取进程pid
public static int GetPidByProcessName(string processName)
{
    Process[] arrayProcess = Process.GetProcessesByName(processName);
    foreach (Process p in arrayProcess)
    {
        return p.Id;
    }
    return 0;
}
//判断进程状态
public void judgeprocessisrunning(string name)
{
    if (GetPidByProcessName(name) == 0)
    {
        MessageBox.Show("指定程序未运行");
    }
    else
        MessageBox.Show("正在运行中");
}

 

posted @ 2016-05-21 20:31  贝尔格里尔斯  阅读(506)  评论(0编辑  收藏  举报