Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

32 or 64 bit machine [duplicate]

Tags:

c#

bit

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.

like image 811
petko_stankoski Avatar asked Apr 10 '26 05:04

petko_stankoski


1 Answers

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.

like image 136
vharavy Avatar answered Apr 11 '26 18:04

vharavy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!