System.Diagnostics.NtProcessManager.GetProcessIdFromHandle C# (CSharp) Method

GetProcessIdFromHandle() public static method

public static GetProcessIdFromHandle ( SafeProcessHandle processHandle ) : int
processHandle Microsoft.Win32.SafeHandles.SafeProcessHandle
return int
        public static int GetProcessIdFromHandle(SafeProcessHandle processHandle)
        {
            Interop.NtDll.NtProcessBasicInfo info = new Interop.NtDll.NtProcessBasicInfo();
            int status = Interop.NtDll.NtQueryInformationProcess(processHandle, Interop.NtDll.NtQueryProcessBasicInfo, info, (int)Marshal.SizeOf(info), null);
            if (status != 0)
            {
                throw new InvalidOperationException(SR.CantGetProcessId, new Win32Exception(status));
            }
            // We should change the signature of this function and ID property in process class.
            return info.UniqueProcessId.ToInt32();
        }

Usage Example

 public static int GetProcessIdFromHandle(Microsoft.Win32.SafeHandles.SafeProcessHandle processHandle)
 {
     if (!IsNt)
     {
         throw new PlatformNotSupportedException(SR.GetString("WinNTRequired"));
     }
     return(NtProcessManager.GetProcessIdFromHandle(processHandle));
 }
All Usage Examples Of System.Diagnostics.NtProcessManager::GetProcessIdFromHandle