How can my program determine if it works on 32-bit or 64-bit Windows?

Here is my question. What is the best way to determine which bit architecture your application is running in?

What I'm looking for: on a 64-bit server, I want my application to read 64-bit data sources (stored in the Software \ Wow6432Node \ ODBC \ ODBC.INI \ ODBC Data Sources key), and if its 32-bit, I I want to read 32-bit data sources (i.e. read from software \ ODBC \ ODBC.INI \ ODBC data sources).

I might miss the point, but I don’t want to worry about what mode my application is running in. I just want to know if the OS is 32 or 64 bit.

[System.Environment.OSVersion.Platform does not seem to cut this for me. Its returning Win32NT on my local xp computer and on the 64-bit win2k8 server (even if all my projects are configured on "any processor")]

+5
source share
5 answers

Try the property Environment.Is64BitOperatingSystem. This is a new one added to .Net 4.0 specifically for checking the type of operating system.

+4
source

, , :

Console.WriteLine(
    "Is 64-bit? {0}",
    (
        System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)) == sizeof(Int64)
            ? "Yes" 
            : "No"
    )
);
+4

, . Software\Wow6432Node 32- 64- .

+3

Wow6432Node . RegistryView, 32- 64- .

+2

All Articles