#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <process.h>
#include <Winternl.h>
#include <Tlhelp32.h.>
#include <tchar.h>
using std::cout;
using std::endl;
DWORD get_ppid(DWORD dwTargetPID) {
PROCESSENTRY32 pe;
pe.dwSize = sizeof PROCESSENTRY32;
DWORD ppid = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
bool bFind = Process32First(hSnap, &pe);
while (bFind) {
if (pe.th32ProcessID == dwTargetPID) {
ppid = pe.th32ParentProcessID;
break;
}
bFind = Process32Next(hSnap, &pe);
}
CloseHandle(hSnap);
return ppid;
}
int main() {
cout << get_ppid(GetCurrentProcessId()) << endl;
return 0;
};