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);
}
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);
}
来源:https://www.cnblogs.com/smdw9522/archive/2007/08/21/863386.html