【c#】读取进程列表判断程序是否已经启动,启动应用...

方法一:

using System.Diagnostics; 


Process[] vProcesses = Process.GetProcesses(); 
foreach (Process vProcess in vProcesses) 
if (vProcess.ProcessName.Equals( "iexplore ", 
StringComparison.OrdinalIgnoreCase)) 
{ 
MessageBox.Show( "IE已经打开 "); 
break; 
}


方法二:

using System.Diagnostics;


Process[] app = Process.GetProcessesByName("AMS");
            if (app.Length > 0)
            {
                MessageBox.Show("请关闭已经启动的程序后再进行尝试");
                return;
            }
            else
            {
                System.Diagnostics.Process.Start("AMS.exe");
            }


杀死进程:查找到对应的进程后就可以调用系统命令杀死指定名称的进程

            Process[] p = Process.GetProcessesByName("AMS");
            foreach (Process ps in p)
            {
                ps.Kill();
            }

启动

用Process类
Process[] myprocess=Process.GetProcessesByName("a");
if(myprocess.length>0)
{
    myprocess[0]. CloseMainWindow();
    myprocess[0].Close();
}
else
{
    Process.Start("a.exe");
}

 

展开阅读全文

没有更多推荐了,返回首页