string vProcessName = "QQ";//定义要查寻的进程名称
Process[] vProcess = Process.GetProcesses();
bool vIsRuning = false;//记录进程是否已经启动 默认为false
try
{
foreach (Process pProcess in vProcess)
{
//在这里将进程统一转换为小写以便正确判断
if (pProcess.ProcessName.ToLower().Trim().Equals(vProcessName.ToLower().Trim()))
{
vIsRuning = true;
break;
}
}
if (vIsRuning)
{
MessageBox.Show(vProcessName + " 进程已经启动");
}
else
{
MessageBox.Show(vProcessName + " 进程没有启动");
}
}
catch (Exception ex)
{
MessageBox.Show("查询过程发生错误,错误信息:" + ex.Message);
}