Узнать родительский процесс - C#
Формулировка задачи:
Здравствуйте, подскажите пожалуйста, как узнать родительский процесс не относящийся к моей программе.
Вроде где то здесь должно быть System.Diagnostics.Process
Но подходящего метода не нашёл((
Решение задачи: «Узнать родительский процесс»
textual
Листинг программы
[StructLayout( LayoutKind.Sequential )] struct PROCESS_BASIC_INFORMATION { public uint ExitStatus; public IntPtr PebBaseAddress; // Zero if 32 bit process try get info about 64 bit process public IntPtr AffinityMask; public int BasePriority; public IntPtr UniqueProcessId; public IntPtr InheritedFromUniqueProcessId; } [DllImport( "ntdll.dll", SetLastError = true, ExactSpelling = true )] private static extern uint NtQueryInformationProcess ( IntPtr ProcessHandle, uint ProcessInformationClass, ref PROCESS_BASIC_INFORMATION ProcessInformation, int ProcessInformationLength, out int ReturnLength ); static void Main ( ) { using ( var process = Process.GetProcessById( 1928 ) ) { var pbi = new PROCESS_BASIC_INFORMATION(); int writed; if ( 0 != NtQueryInformationProcess( process.Handle, 0, ref pbi, Marshal.SizeOf( pbi ), out writed ) || writed == 0 ) throw new Win32Exception( Marshal.GetLastWin32Error() ); Console.WriteLine( "Parent ID: " + pbi.InheritedFromUniqueProcessId ); } Console.ReadKey(); }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д