public static IntPtr OpenProcess(Pinvokes.ProcessAccessFlags processAccess, bool bInheritHandle, int processId) { IntPtr handle = Pinvokes.OpenProcess(processAccess, bInheritHandle, processId); if (handle == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return(handle); }