命名空间是using System.Diagnostics;

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
Process p = Process.Start("notepad.exe");
p.WaitForExit();//关键,等待外部程序退出后才能往下执行

 

 

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);
   }
  

c#调用外部程序


命名空间是 using System.Diagnostics;

程序源码为:
privater void StaartForm()
{
     Process MyProcess = new Process();
     MyProcess.StartInfo.FileName = "d:/aaa.exe";//外部程序路径
     MyProcess.StartInfo.Verb = "Open";
     MyProcess.StartInfo.CreateNoWindow = true;
     MyProcess.Start();
}
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄