1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| BOOL GetProcessID(const CString& szName, DWORD& ProcessID) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if (hSnapshot == INVALID_HANDLE_VALUE) { return FALSE; } PROCESSENTRY32 processList; processList.dwSize=sizeof(PROCESSENTRY32); BOOL bResult=Process32First(hSnapshot,&processList); BOOL bReturn=FALSE; while(bResult) { CString str=processList.szExeFile; if(str==szName) { ProcessID = processList.th32ProcessID; bReturn=TRUE; bResult=FALSE; break; } else { bResult=Process32Next(hSnapshot,&processList); } } ::CloseHandle(hSnapshot); return bReturn; }
|