Skip to content

Instantly share code, notes, and snippets.

@tecnocrata
Created February 12, 2014 13:17
Show Gist options
  • Select an option

  • Save tecnocrata/8955392 to your computer and use it in GitHub Desktop.

Select an option

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?)
//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