Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        private static int GetProcessBitness(IntPtr hProcess)
        {
            if (System.Environment.Is64BitOperatingSystem)
            {
                bool wow64;
                if (!ProcessNativeMethods.IsWow64Process(hProcess, out wow64))
                {
                    return(32);
                }
                if (wow64)
                {
                    return(32);
                }

                return(64);
            }
            else
            {
                return(32);
            }
        }