コード例 #1
0
        // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms684139%28v=vs.85%29.aspx
        public static bool?IsProcess64Bit(int processId)
        {
            if (!Environment.Is64BitOperatingSystem)
            {
                return(false);
            }

            // if this method is not available in your version of .NET, use GetNativeSystemInfo via P/Invoke instead
            using (var processHandle = ProcessNativeMethods.OpenProcess(processId, ProcessAccessFlags.QueryLimitedInformation))
            {
                if (processHandle.IsInvalid)
                {
                    var errorCode = NativeMethods.GetLastError();
                    if (errorCode == 5)
                    {
                        return(null);//no access
                    }
                    throw new Win32Exception(errorCode);
                }

                if (!ProcessNativeMethods.IsWow64Process(processHandle.DangerousGetHandle(), out var isWow64))
                {
                    var errorCode = NativeMethods.GetLastError();

                    throw new Win32Exception(errorCode);
                }

                return(!isWow64);
            }
        }
コード例 #2
0
        private static bool IsProcessElevated(Process process)
        {
            using (var processHandle = ProcessNativeMethods.OpenProcess(process, ProcessAccessFlags.QueryInformation))
            {
                if (processHandle.IsInvalid)
                {
                    var error = Marshal.GetLastWin32Error();

                    return(error == NativeMethods.ERROR_ACCESS_DENIED);
                }

                return(false);
            }
        }