c#判断程序是否运行

   string name = "aaa";//程序进程名称
   int ProgressCount = 0123456;//判断进程是否运行的标识
   Process[] prc = Process.GetProcesses(); 
   foreach(Process pr in prc) //遍历整个进程
   {  
            if (name == pr.ProcessName)  //如果进程存在
            {     
                    ProgressCount = 0; //计数器清空
                     return;
            } 
   }
   if(ProgressCount!=0)//如果计数器不为0,说名所指定程序没有运行
   {
    try
    {
     //调用外部程序
     Process MyProcess = new Process();
     MyProcess.StartInfo.FileName = "d:/aaa.exe";
     MyProcess.StartInfo.Verb = "Open";
     MyProcess.StartInfo.CreateNoWindow = true;
     MyProcess.Start();
    }
    catch(Exception d)
    {
     MessageBox.Show(d.Message+"","提示!!!!");
    }
   }
   else
   {
    MessageBox.Show("对不起,本地已经有系统正在运行!\n.","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
   }

posted on 2007-08-21 01:32  什么的外  阅读(1600)  评论(0)    收藏  举报

导航