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;
}