C++ 判断进程是否存在

来源:互联网 发布:华为v9网络错误 编辑:程序博客网 时间:2024/05/16 15:28
原文出处:http://blog.csdn.net/zhensoft163/article/details/7967993
#include <windows.h>    
#include "psapi.h"    #include"stdio.h"  #include <tlhelp32.h>  
//判断进程是否存在  //2012-09-10  BOOL FindProcess()  {      int i=0;      PROCESSENTRY32 pe32;      pe32.dwSize = sizeof(pe32);       HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);      if(hProcessSnap == INVALID_HANDLE_VALUE)      {          i+=0;      }      BOOL bMore = ::Process32First(hProcessSnap, &pe32);      while(bMore)      {          //printf(" 进程名称:%s \n", pe32.szExeFile);          if(stricmp("进程名",pe32.szExeFile)==0)          {              //printf("进程运行中");              i+=1;          }          bMore = ::Process32Next(hProcessSnap, &pe32);      }      if(i>1){           //大于1,排除自身          return true;      }else{          return false;      }  }