判断本地计算机是否启动指定进程

 

            string vProcessName = "QQ";//定义要查寻的进程名称

            Process[] vProcess = Process.GetProcesses();
            bool vIsRuning = false;//记录进程是否已经启动 默认为false

            try
            {
                foreach (Process pProcess in vProcess)
                {

                   //在这里将进程统一转换为小写以便正确判断
                    if (pProcess.ProcessName.ToLower().Trim().Equals(vProcessName.ToLower().Trim()))
                    {
                        vIsRuning = true;
                        break;
                    }
                }

                if (vIsRuning)
                {
                   MessageBox.Show(vProcessName + " 进程已经启动");
                }
                else
                {
                    MessageBox.Show(vProcessName + " 进程没有启动");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("查询过程发生错误,错误信息:" + ex.Message);
            }

posted @ 2009-02-16 14:52  phcis  阅读(433)  评论(0编辑  收藏  举报