开发者

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

Here's my question. What is the best way to determine what bit architecture your app is running on?

What I am looking to do: On a 64 bit server I want my app to read 64 bit datasources (stored in reg key Software\Wow6432Node\ODBC\ODBC.INI\ODBC Data Sources) and if its 32 bit I want to read 32 bit datasources, (i.e. Read from Software\ODBC\ODBC.INI\ODBC Data Sources).

I might be missing the point, but I don't want to care what mode my app is running in. I simply want to know if the OS is 32 or 64 bit.

[System.Environment.OSVersion.Platform doesn't seem to be cutting it for me. Its returning Win32NT on my local xp machine and on a win2k8 64 bit server (even when all my p开发者_开发技巧rojects are set to target 'any cpu')]


You shouldn't even worry about this, normally. The system automatically redirects registry queries to Software\Wow6432Node when running a 32-bit app on a 64-bit platform.


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


Simple, safe, framework version agnostic solution without going to the registry:

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


You should not read Wow6432Node directly. Use RegistryView to specify a 32-bit view when running as a 64-bit app.


How to detect Windows 64 bit platform with .net? might be helpful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜