Last active
August 29, 2015 14:02
-
-
Save yufanpi/6ae886919dba2b96b9ce to your computer and use it in GitHub Desktop.
GetProcessID by process name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <TlHelp32.h> | |
BOOL GetProcessID(const wchar_t* wszProcessName, DWORD& dwProcID) | |
{ | |
HANDLE hSnapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, dwProcID); | |
PROCESSENTRY32 pe = { sizeof(pe) }; | |
BOOL bOk = ::Process32First(hSnapShot, &pe); | |
while (bOk) | |
{ | |
if (wcsstr(pe.szExeFile, wszProcessName) != NULL) | |
{ | |
dwProcID = pe.th32ProcessID; | |
return TRUE; | |
} | |
bOk = ::Process32Next(hSnapShot, &pe); | |
} | |
::CloseHandle(hSnapShot); | |
return FALSE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment