Пример #1
0
        private static bool Is32BitProcessOn64BitProcessor()
        {
            IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate();

            if (fnDelegate == null)
            {
                return(false);
            }

            bool isWow64;

            try
            {
                bool retVal = fnDelegate.Invoke(Process.GetCurrentProcess().Handle, out isWow64);

                if (retVal == false)
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }


            return(isWow64);
        }
Пример #2
0
        // <summary>
        // Detect if the msbuild is running under WOW64 environment.
        // </summary>
        static private bool IsWow64CLRRun()
        {
            bool   isWow64    = false;
            IntPtr NullIntPtr = new IntPtr(0);

            IntPtr kernel32Dll = LoadLibrary(Kernel32Dll);

            if (kernel32Dll != NullIntPtr)
            {
                try
                {
                    IntPtr isWow64ProcessHandle = GetProcAddress(kernel32Dll, IsWow64ProcessMethodName);

                    // if the entry point is missing, it cannot be Wow64
                    if (isWow64ProcessHandle != NullIntPtr)
                    {
                        // entry point present, check if running in WOW64
                        IsWow64ProcessDelegate isWow64Process = (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer(isWow64ProcessHandle, typeof(IsWow64ProcessDelegate));
                        isWow64Process(GetCurrentProcess(), out isWow64);
                    }
                }
                finally
                {
                    FreeLibrary(kernel32Dll);
                }
            }

            return(isWow64);
        }
Пример #3
0
        public static bool IsWow64()
        {
            bool   isWow64     = false;
            IntPtr functionPtr = WinBaseApi.GetProcAddress(WinBaseApi.GetModuleHandle("kernel32"), "IsWow64Process");

            if (functionPtr != IntPtr.Zero)
            {
                IsWow64ProcessDelegate del = (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(IsWow64ProcessDelegate));
                del(WinBaseApi.GetCurrentProcess(), out isWow64);
            }
            return(isWow64);
        }
Пример #4
0
        private static bool Is32BitProcessOn64BitProcessor()
        {
            IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate();

            if (fnDelegate == null)
            {
                return(false);
            }

            bool isWow64;
            bool retVal = fnDelegate.Invoke(Process.GetCurrentProcess().Handle, out isWow64);

            return(retVal && isWow64);
        }
Пример #5
0
        private static string GetCurrentProcessArchitecture()
        {
            string str    = null;
            IntPtr module = NativeMethodsShared.LoadLibrary("kernel32.dll");

            try
            {
                if (!(module != NativeMethodsShared.NullIntPtr))
                {
                    return(str);
                }
                IntPtr procAddress = NativeMethodsShared.GetProcAddress(module, "IsWow64Process");
                if (procAddress == NativeMethodsShared.NullIntPtr)
                {
                    return("x86");
                }
                IsWow64ProcessDelegate delegateForFunctionPointer = (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(IsWow64ProcessDelegate));
                bool flag = false;
                if (!delegateForFunctionPointer(Process.GetCurrentProcess().Handle, out flag))
                {
                    return(str);
                }
                if (flag)
                {
                    return("x86");
                }
                NativeMethodsShared.SYSTEM_INFO lpSystemInfo = new NativeMethodsShared.SYSTEM_INFO();
                NativeMethodsShared.GetSystemInfo(ref lpSystemInfo);
                switch (lpSystemInfo.wProcessorArchitecture)
                {
                case 0:
                    return("x86");

                case 6:
                    return("IA64");

                case 9:
                    return("AMD64");
                }
                str = null;
            }
            finally
            {
                if (module != NativeMethodsShared.NullIntPtr)
                {
                    NativeMethodsShared.FreeLibrary(module);
                }
            }
            return(str);
        }
Пример #6
0
        /// <summary>
        /// Gets a value indicating whether the current process is running as 32-bit on a 64-bit processor.
        /// </summary>
        /// <returns>True if the current processor is 64-bit.</returns>
        private static bool Is32BitProcessOn64BitProcessor()
        {
            bool result = false;

            if (IntPtr.Size == 4)
            {
                IsWow64ProcessDelegate functionDelegate = GetIsWow64ProcessDelegate();
                bool isWow64;

                if (functionDelegate != null && functionDelegate.Invoke(Process.GetCurrentProcess().Handle, out isWow64))
                {
                    result = isWow64;
                }
            }

            return(result);
        }
Пример #7
0
    private static bool Is32BitProcessOn64BitProcessor()
    {
        IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate();

        if (fnDelegate == null)
        {
            return(false);
        }

        bool isWow64;
        bool retVal = fnDelegate.Invoke(System.Diagnostics.Process.GetCurrentProcess().Handle, out isWow64);

        if (retVal == false)
        {
            return(false);
        }

        return(isWow64);
    }
Пример #8
0
        private static bool Is32BitProcessOn64BitProcessor()
        {
            IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate();

            if (fnDelegate == null)
            {
                return(false);
            }

            bool isWow64;
            bool retVal = fnDelegate.Invoke(AppInfo.CurrentProcess.Handle, out isWow64);

            if (retVal == false)
            {
                return(false);
            }

            return(isWow64);
        }
Пример #9
0
    public static bool Is64BitWindows()
    {
        bool flag;

        if (IntPtr.Size == 8)
        {
            return(true);
        }
        IsWow64ProcessDelegate delegate2 = GetIsWow64ProcessDelegate();

        if (delegate2 == null)
        {
            return(false);
        }
        if (!delegate2(Process.GetCurrentProcess().Handle, out flag))
        {
            return(false);
        }
        return(flag);
    }
Пример #10
0
        /// <summary>
        /// Gets the processor architecture of the currently running process
        /// </summary>
        /// <returns>null if unknown architecture or error, one of the known architectures otherwise</returns>
        static private string GetCurrentProcessArchitecture()
        {
            string architecture = null;

            IntPtr kernel32Dll = NativeMethodsShared.LoadLibrary("kernel32.dll");

            try
            {
                if (kernel32Dll != NativeMethodsShared.NullIntPtr)
                {
                    // This method gets the current architecture from the currently running msbuild.
                    // If the entry point is missing, we're running on Kernel older than WinXP
                    // http://msdn.microsoft.com/en-us/library/ms684139.aspx
                    IntPtr isWow64ProcessHandle = NativeMethodsShared.GetProcAddress(kernel32Dll, "IsWow64Process");

                    if (isWow64ProcessHandle == NativeMethodsShared.NullIntPtr)
                    {
                        architecture = ProcessorArchitecture.X86;
                    }
                    else
                    {
                        // entry point present, check if running in WOW
                        IsWow64ProcessDelegate isWow64Process = (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer(isWow64ProcessHandle, typeof(IsWow64ProcessDelegate));
                        bool isWow64 = false;
                        bool success = isWow64Process(Process.GetCurrentProcess().Handle, out isWow64);

                        if (success)
                        {
                            // if it's running on WOW, must be an x86 process
                            if (isWow64)
                            {
                                architecture = ProcessorArchitecture.X86;
                            }
                            else
                            {
                                // it's a native process. Check the system architecture to determine the process architecture.
                                NativeMethodsShared.SYSTEM_INFO systemInfo = new NativeMethodsShared.SYSTEM_INFO();

                                NativeMethodsShared.GetSystemInfo(ref systemInfo);

                                switch (systemInfo.wProcessorArchitecture)
                                {
                                case NativeMethodsShared.PROCESSOR_ARCHITECTURE_INTEL:
                                    architecture = ProcessorArchitecture.X86;
                                    break;

                                case NativeMethodsShared.PROCESSOR_ARCHITECTURE_AMD64:
                                    architecture = ProcessorArchitecture.AMD64;
                                    break;

                                case NativeMethodsShared.PROCESSOR_ARCHITECTURE_IA64:
                                    architecture = ProcessorArchitecture.IA64;
                                    break;

                                case NativeMethodsShared.PROCESSOR_ARCHITECTURE_ARM:
                                    architecture = ProcessorArchitecture.ARM;
                                    break;

                                // unknown architecture? return null
                                default:
                                    architecture = null;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (kernel32Dll != NativeMethodsShared.NullIntPtr)
                {
                    NativeMethodsShared.FreeLibrary(kernel32Dll);
                }
            }

            return(architecture);
        }