进程是否运行判断
如何判断进程中存在*.exe若不存在则加载,存在则提示用户该进程已经运行!c#实现!
--------------------编程问答-------------------- Process[] pco=Process.GetProcesses();
foreach (Process p in pco)
{
if (p.p.ProcessName == "你想检查的进程")
{
}
} --------------------编程问答-------------------- Process.GetProcessesByName("ProcessName"); --------------------编程问答-------------------- 你写的程序得不到我要的结果
我改了下还是有问题
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Process[] pco = Process.GetProcesses();
foreach (Process p in pco)
{
if (p.ProcessName == "notepad.exe")
{
MessageBox.Show("已经存在一个进程了");
break;
}
else
{
System.Diagnostics.Process.Start("notepad.exe");
break;
}
}
}
}
}
是不是哪写错了?
--------------------编程问答-------------------- 多了个exe --------------------编程问答-------------------- 还是不行啊! --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
bool isFind = false;
Process[] process = Process.GetProcesses();
foreach (Process p in process)
{
if (p.ProcessName == "notepad")
{
label1.Text = "已经运行了一个notepad.exe";
isFind = true;
break;
}
}
if (isFind == false)
System.Diagnostics.Process.Start("notepad.exe");
}
}
}
不好意思,原来程序有问题。
现在OK了!
谢谢大伙啦!
补充:.NET技术 , C#