/// <summary> /// Gets a boolean value indicating whether the access to a process using the AllAccess flag is denied or not. /// </summary> /// <param name="pid">The process ID of the process</param> /// <returns>True if denied and false if not.</returns> private static bool TestProcessAccessUsingAllAccessFlag(uint pid) { IntPtr processHandle = NativeMethods.OpenProcess(ProcessAccessFlags.AllAccess, true, (int)pid); if (Win32Helpers.GetLastError() == 5) { // Error 5 = ERROR_ACCESS_DENIED _ = Win32Helpers.CloseHandleIfNotNull(processHandle); return(true); } else { _ = Win32Helpers.CloseHandleIfNotNull(processHandle); return(false); } }