C#判断指定进程是否存在 想用C#实现判断指定进程是否存在,若存在,则杀掉进程或者弹出一个对话框提示用户,比如监控QQ进程,如何实现呢??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Process[] processes = Process.GetProcessesByName(processName); 返回 Process[] pro = Process.GetProcessesByName("Test"); for (int i = 0; i < pro.Length; i++) { pro[i].Kill(); } [DllImport("user32.dll", EntryPoint = "FindWindow")] public static extern int FindWindow( string lpClassName, string lpWindowName ); int hWnd = FindWindow(null, "QQ"); if (hWnd == 0){ //不存在}else{//存在} 解决了,贴出来,供大家参考命名空间是using System.Diagnostics;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); } name.Equals(pr.ProcessName)private void KillProcess(string processName){System.Diagnostics.Process myproc= new System.Diagnostics.Process();try{foreach (Process thisproc in Process.GetProcessesByName(processName)) {if(!thisproc.CloseMainWindow()){thisproc.Kill();}}}catch(Exception Exc){} GC.Collect();} Process 事件更改!! 小说阅读器如何增加书签? C#WinForm中如何实现窗体的动态加载 如何判断数据是否是数字?在线等! 请问水晶报表显示的文本为什么分这么开?可以调紧缩一点吗? C#中怎么把刚添加到表中的一些数据显示在datagrid中 数据库中的image类型显示到pictureBox出错 关于Msmq的保存问题 问一个关于dataGrid的一个细节问题。 errorprovider 问题 请教listview默认选中。
Process[] processes = Process.GetProcessesByName(processName);
返回
Process[] pro = Process.GetProcessesByName("Test");
for (int i = 0; i < pro.Length; i++)
{
pro[i].Kill();
}
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(
string lpClassName,
string lpWindowName
);
int hWnd = FindWindow(null, "QQ");
if (hWnd == 0)
{
//不存在
}
else
{
//存在
}
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);
}
private void KillProcess(string processName)
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
try{
foreach (Process thisproc in Process.GetProcessesByName(processName)) {
if(!thisproc.CloseMainWindow()){
thisproc.Kill();
}
}
}
catch(Exception Exc)
{
}
GC.Collect();
}