", mbo.GetPropertyValue("ServicePackMajorVersion").ToString(), mbo.GetPropertyValue("ServicePackMinorVersion").ToString())
Public static bool IsWin64BitOS(this OperatingSystem os)Įlse// 32-bit programs run on both 32-bit and 64-bit Windows Some possible usage is shown below: bool bIs64BitOS = 64BitOS() īool bIs64BitProc = ().Is64BitProc()
It uses extension methods for easy code reuse. This is a solution based on Microsoft's code at. The environment must be an x86 environment.Įxample usage: EnvironmentHelper.Is64BitOperatingSystem() If (IsWow64Process(GetCurrentProcess(), out result) & result) IntPtr processAddress = GetProcAddress(moduleHandle, "IsWow64Process") IntPtr moduleHandle = GetModuleHandle("kernel32") Check if this process is an x86 process running on an 圆4 environment. If it is, it will only run on 圆4 environments, thus, the environment must be 圆4. Check if this process is natively an 圆4 process. Static extern IntPtr GetProcAddress(IntPtr hModule, string procName) With that in mind, here's what I've come up with: public static class EnvironmentHelper Using dotPeek helps to see how the framework actually does it. There is a WMI version available as well (for testing remote machines). Static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process) Static extern IntPtr GetProcAddress(IntPtr hModule,
Static extern IntPtr GetModuleHandle(string moduleName) Static extern IntPtr GetCurrentProcess()
Return (GetProcAddress(moduleHandle, methodName) != IntPtr.Zero)
IntPtr moduleHandle = GetModuleHandle(moduleName) Static bool DoesWin32MethodExist(string moduleName, string methodName) / exists in the export table of the module specified by moduleName. / The function returns true if the method specified by methodName / The function determins whether a method exists in the export IsWow64Process(GetCurrentProcess(), out flag)) & flag) Return ((DoesWin32MethodExist("kernel32.dll", "IsWow64Process") & Detect whether the current process is a 32-bit process If (IntPtr.Size = 8) // 64-bit programs run only on Win64Įlse // 32-bit programs run on both 32-bit and 64-bit Windows Public static bool Is64BitOperatingSystem() / The function returns true if the operating system is 64-bit / The function determines whether the current operating system is a Microsoft has put a code sample for this: IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate() īool retVal = fnDelegate.Invoke(Process.GetCurrentProcess().Handle, out isWow64) Private static bool Is32BitProcessOn64BitProcessor() Return (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)fnPtr, typeof(IsWow64ProcessDelegate)) IntPtr fnPtr = GetProcAddress(handle, "IsWow64Process") Private static IsWow64ProcessDelegate GetIsWow64ProcessDelegate() If (IntPtr.Size = 8 || (IntPtr.Size = 4 & Is32BitProcessOn64BitProcessor())) Private delegate bool IsWow64ProcessDelegate( IntPtr handle, out bool isWow64Process) Public extern static IntPtr GetProcAddress(IntPtr hwnd, string procedureName) Public extern static IntPtr LoadLibrary(string libraryName) (would have posted as a comment, but I'm a new user!) Just figured I'd post it so other people didn't have roll it by hand. This is just an implementation of what's suggested above by Bruno Lopez, but works on Win2k + all WinXP service packs. If (!IsWow64Process(p.Handle, out retVal)) Using (Process p = Process.GetCurrentProcess()) Public static bool InternalCheckIsWow64() Private static extern bool IsWow64Process( Static bool is64BitOperatingSystem = is64BitProcess || InternalCheckIsWow64() My solution: static bool is64BitProcess = (IntPtr.Size = 8)
How to detect programmatically whether you are running on 64-bit Windows If this returns true, you are running in a 32-bit process on 64-bit Windows. NET you can do so by checking IntPtr.Size), and if you are running in a 32-bit process, you still have to call the Win API function IsWow64Process. NET Framework 2.0 on 64-bit Windows (it would return 32-bit).Īs Microsoft's Raymond Chen describes, you have to first check if running in a 64-bit process (I think in. IntPtr.Size won't return the correct value if running in 32-bit. NET Framework 4.0, you can just check Environment.Is64BitOperatingSystem. UPDATE: As Joel Coehoorn and others suggest, starting at.