public static int GetParentProcessId() { ProcessBasicInformation ProccessInfo = new ProcessBasicInformation(); IntPtr ProcHandle = Process.GetCurrentProcess().Handle; uint RetLength = 0; NtQueryInformationProcess(ProcHandle, PROCESSBASICINFORMATION, ref ProccessInfo, Marshal.SizeOf(ProccessInfo), ref RetLength); return ProccessInfo.InheritedFromUniqueProcessId.ToInt32(); }
private static extern int NtQueryInformationProcess(IntPtr handle, uint processinformationclass, ref ProcessBasicInformation processInformation, int processInformationLength, ref uint returnLength);