#include #include #include BOOL GetProcessInfo(DWORD dwProcessId, PROCESSENTRY32* pProcessInfo) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) { return FALSE; } PROCESSENTRY32 pe32 = { 0 }; pe32.dwSize = sizeof(PROCESSENTRY32); BOOL bProcessFound = FALSE; if (Process32First(hSnapshot, &pe32)) { do { if (pe32.th32ProcessID == dwProcessId) { bProcessFound = TRUE; if (pProcessInfo != NULL) { memcpy(pProcessInfo, &pe32, sizeof(PROCESSENTRY32)); } break; } } while (Process32Next(hSnapshot, &pe32)); } CloseHandle(hSnapshot); return bProcessFound; } int main() { DWORD processId = 4916; // 対象プロセスのIDを指定する PROCESSENTRY32 pe32 = { 0 }; pe32.dwSize = sizeof(PROCESSENTRY32); if (GetProcessInfo(processId, &pe32)) { printf("Process Name: %ws\n", pe32.szExeFile); printf("Process ID: %lu\n", pe32.th32ProcessID); printf("Parent Process ID: %lu\n", pe32.th32ParentProcessID); } else { printf("Process not found.\n"); } return 0; }