Created
February 12, 2014 13:17
-
-
Save tecnocrata/8955392 to your computer and use it in GitHub Desktop.
Determine if I'm running on 64 bits (How to detect Windows 64-bit platform with .NET?)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://stackoverflow.com/questions/336633/how-to-detect-windows-64-bit-platform-with-net | |
| bool is64BitProcess = (IntPtr.Size == 8); | |
| bool is64BitOperatingSystem = is64BitProcess || InternalCheckIsWow64(); | |
| [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] | |
| [return: MarshalAs(UnmanagedType.Bool)] | |
| private static extern bool IsWow64Process( | |
| [In] IntPtr hProcess, | |
| [Out] out bool wow64Process | |
| ); | |
| public static bool InternalCheckIsWow64() | |
| { | |
| if ((Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1) || | |
| Environment.OSVersion.Version.Major >= 6) | |
| { | |
| using (Process p = Process.GetCurrentProcess()) | |
| { | |
| bool retVal; | |
| if (!IsWow64Process(p.Handle, out retVal)) | |
| { | |
| return false; | |
| } | |
| return retVal; | |
| } | |
| } | |
| else | |
| { | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment