3

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.

Community
  • 1
  • 1
petko_stankoski
  • 10,459
  • 41
  • 127
  • 231

2 Answers2

2

Function IsWow64Process determines whether the specified process is running under WOW64. So basically it returns true when called for the 32-bit process running under 64-bit OS.

vharavy
  • 4,881
  • 23
  • 30
-1

You can use Environment.Is64BitOperatingSystem.

See this question for more answers and discussion.


Edit: Oh, didn't see the question is about .net 2.0. (Keeping the answer for reference.)

Community
  • 1
  • 1
Vlad
  • 35,022
  • 6
  • 77
  • 199