Possible Duplicate:
How to detect Windows 64 bit platform with .net?
I’m using this code ti check if the machine is 64 or 32 bit:
public static string GetOSBit()
{
bool is64bit = Is64Bit();
if (is64bit)
return "64 bit";
else
return "32 bit";
}
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);
public static bool Is64Bit()
{
bool retVal;
IsWow64Process(Process.GetCurrentProcess().Handle, out retVal);
return retVal;
}
I have a 32 bit machine and it works ok for me. It returns “32 bit”. My friend however also has a 32 bit machine, but has installed virtual machine which is 64 bit. The code above returns “32 bit” for her virtual machine, although it’s 64 bit.
I work in C#, .Net 2.0.
Function
IsWow64Processdetermines whether the specified process is running under WOW64. So basically it returnstruewhen called for the 32-bit process running under 64-bit OS.