VC根据进程名获得进程ID


DWORD GetProcessIDFromName(char *name)
{
 HANDLE snapshot;
 PROCESSENTRY32 processinfo;
 processinfo.dwSize = sizeof(processinfo);
 snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
 if(snapshot == NULL)
  return FALSE;

 BOOL status = Process32First(snapshot, &processinfo);
 while(status)
 {
  if(_stricmp(name,processinfo.szExeFile)==0)
   return processinfo.th32ProcessID;
  status = Process32Next(snapshot,&processinfo);
 }
 return -1;
}

posted on 2012-07-25 22:43  wps712  阅读(5502)  评论(0编辑  收藏  举报

导航