CreateToolhelp32Snapshot
HANDLE CreateToolhelp32Snapshot(
[in] DWORD dwFlags,
[in] DWORD th32ProcessID
);인자
설명
보편적인 값
Example
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
using namespace std;
DWORD getProcId(const wchar_t* processName) {
// 메모리에 로드된 프로세스 스냅샷 생성
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) {
wcout << L"Failed to take a snapshot" << endl;
return 0;
}
// 스냅샷을 순회하며 저장할 프로세스 변수 생성
PROCESSENTRY32W pe;
pe.dwSize = sizeof(PROCESSENTRY32W);
if (Process32FirstW(hSnapshot, &pe)) {
do {
// 대소문자 구분 없이 비교하여 일치할 경우 조건분기
if (_wcsicmp(pe.szExeFile, processName) == 0) {
wcout << L"Succeed to find a process : " << pe.szExeFile << endl;
CloseHandle(hSnapshot);
return pe.th32ProcessID;
}
} while (Process32NextW(hSnapshot, &pe));
}
CloseHandle(hSnapshot);
wcout << L"Failed to find a process in memory" << endl;
return 0;
}
int main() {
DWORD pid = getProcId(L"notepad.exe");
return 0;
}References
Last updated