-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_pid.cpp
More file actions
40 lines (30 loc) · 863 Bytes
/
find_pid.cpp
File metadata and controls
40 lines (30 loc) · 863 Bytes
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
36
37
38
39
40
#include "find_pid.h"
// Function to find PID by process name
DWORD GetPIDByProcessName(const std::wstring& processName) {
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) {
return 0;
}
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnapshot, &pe32)) {
CloseHandle(hSnapshot);
return 0;
}
do {
if (wcscmp(pe32.szExeFile, processName.c_str()) == 0) {
CloseHandle(hSnapshot);
return pe32.th32ProcessID;
}
} while (Process32Next(hSnapshot, &pe32));
CloseHandle(hSnapshot);
return 0;
}
DWORD get_pid(std::wstring processName ) {
DWORD pid = GetPIDByProcessName(processName);
if (pid != 0) {
}
else {
}
return pid;
}