Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <tlhelp32.h>
- int main(int argc, char *argv[])
- {
- int pid = -1;
- HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- PROCESSENTRY32 pe = { 0 };
- pe.dwSize = sizeof(PROCESSENTRY32);
- //assume first arg is the PID to get the PPID for, or use own PID
- if (argc > 1) {
- pid = atoi(argv[1]);
- } else {
- pid = GetCurrentProcessId();
- }
- if( Process32First(h, &pe)) {
- do {
- if (pe.th32ProcessID == pid) {
- printf("PID: %i; PPID: %in", pid, pe.th32ParentProcessID);
- }
- } while( Process32Next(h, &pe));
- }
- CloseHandle(h);
- }
- ULONG_PTR GetParentProcessId() // By Napalm @ NetCore2K
- {
- ULONG_PTR pbi[6];
- ULONG ulSize = 0;
- LONG (WINAPI *NtQueryInformationProcess)(HANDLE ProcessHandle, ULONG ProcessInformationClass,
- PVOID ProcessInformation, ULONG ProcessInformationLength, PULONG ReturnLength);
- *(FARPROC *)&NtQueryInformationProcess =
- GetProcAddress(LoadLibraryA("NTDLL.DLL"), "NtQueryInformationProcess");
- if(NtQueryInformationProcess){
- if(NtQueryInformationProcess(GetCurrentProcess(), 0,
- &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi))
- return pbi[5];
- }
- return (ULONG_PTR)-1;
- }
Add Comment
Please, Sign In to add comment