/// <summary>
 /// Gets the parent process of a specified process.
 /// </summary>
 /// <returns>A Process object representing the parent.</returns>
 public static Process GetParentProcess(Process process)
 {
     return(ParentProcessUtilities.GetParentProcess(process.Id));
 }
        private static void DescribeProcesses(Process[] processes)
        {
            //Sort in ascending order by PID
            processes = processes.OrderBy(p => p.Id).ToArray();

            foreach (Process process in processes)
            {
                //Get the PID
                ProcessDetails details = new ProcessDetails();
                details.name = process.ProcessName;
                details.pid  = process.Id;

                try
                {
                    //Get the PPID
                    Process parent = ParentProcessUtilities.GetParentProcess(process.Id);
                    if (parent != null)
                    {
                        details.ppid = parent.Id;
                    }
                    else
                    {
                        details.ppid = -1;
                    }
                }
                //Parent is no longer running
                catch (InvalidOperationException)
                {
                    details.ppid = -1;
                }


                //Check the architecture
                try
                {
                    if (ProcessInspector.IsWow64Process(process))
                    {
                        details.arch = "x86";
                    }
                    else
                    {
                        details.arch = "x64";
                    }
                }
                catch
                {
                    details.arch = "*";
                }

                try
                {
                    //Determine whether or not the process is managed (has the CLR loaded).
                    details.managed = ProcessInspector.IsCLRLoaded(process);
                }
                //Process is no longer running
                catch (InvalidOperationException)
                {
                    details.managed = false;
                }


                try
                {
                    //Gets the Session of the Process
                    details.session = process.SessionId;
                }
                //Process is no longer running
                catch (InvalidOperationException)
                {
                    details.session = -1;
                }


                try
                {
                    //Gets the Integrity Level of the process
                    details.integrity = TokenInspector.GetIntegrityLevel(process);
                }
                //Process is no longer running
                catch (InvalidOperationException)
                {
                    details.integrity = TokenInspector.IntegrityLevel.Unknown;
                }


                try
                {
                    //Gets the User of the Process
                    details.user = ProcessInspector.GetProcessUser(process);
                }
                //Process is no longer running
                catch (InvalidOperationException)
                {
                    details.user = "";
                }

                Console.WriteLine("{0,-30} {1,-10} {2,-10} {3,-10} {4,-10} {5,-10} {6,-10} {7}", details.name, details.pid, details.ppid, details.arch, details.managed, details.session, details.integrity, details.user);
            }
        }