Created
August 2, 2017 00:06
-
-
Save mattn/0fadb4010a53bf913b267ffb2ceb71b0 to your computer and use it in GitHub Desktop.
This file contains 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 <stdio.h> | |
#include <windows.h> | |
#include <tlhelp32.h> | |
#include <psapi.h> | |
int | |
main(int argc, char* argv[]) { | |
int pid = -1, ppid = 1; | |
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | |
PROCESSENTRY32 pe = { 0 }; | |
pe.dwSize = sizeof(PROCESSENTRY32); | |
pid = GetCurrentProcessId(); | |
if ( Process32First(h, &pe)) { | |
do { | |
if (pe.th32ProcessID == pid) { | |
ppid = pe.th32ParentProcessID; | |
break; | |
} | |
} while( Process32Next(h, &pe)); | |
} | |
if (Process32First(h, &pe)) { | |
do { | |
if (pe.th32ParentProcessID == ppid) { | |
HANDLE hp = OpenProcess(PROCESS_ALL_ACCESS, 0, pe.th32ProcessID); | |
if (hp) { | |
char fname[MAX_PATH]; | |
DWORD c; | |
fname[0] = 0; | |
c = GetModuleFileNameEx(hp, NULL, fname, sizeof(fname)); | |
fname[c] = 0; | |
puts(fname); | |
CloseHandle(hp); | |
} | |
} | |
} while( Process32Next(h, &pe)); | |
} | |
CloseHandle(h); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment