Created
July 12, 2021 09:50
-
-
Save gnh1201/1ab1127da8d7cb6b658d9345dfa4432c to your computer and use it in GitHub Desktop.
Example of get process handle 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 <cstdio> | |
| #include <windows.h> | |
| #include <stdio.h> | |
| #include <tlhelp32.h> | |
| int main(int, char* []) | |
| { | |
| PROCESSENTRY32 entry; | |
| entry.dwSize = sizeof(PROCESSENTRY32); | |
| const wchar_t* processName = L"sample.exe"; | |
| int check = 0; | |
| HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); | |
| if (Process32First(snapshot, &entry) == TRUE) | |
| { | |
| while (Process32Next(snapshot, &entry) == TRUE) | |
| { | |
| if (_wcsicmp(entry.szExeFile, processName) == 0) | |
| { | |
| HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); | |
| // Do stuff.. | |
| check = 1; | |
| CloseHandle(hProcess); | |
| break; | |
| } | |
| else | |
| { | |
| check = 0; | |
| } | |
| } | |
| } | |
| if (check == 1) | |
| { | |
| printf("찾음\n"); | |
| } | |
| else | |
| { | |
| printf("못찾음\n"); | |
| } | |
| CloseHandle(snapshot); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment