我的程序如何确定它是在 32 位还是 64 位 Windows 上运行?
这是我的问题。确定您的应用程序运行在哪种位架构上的最佳方法是什么?
我想要做什么:在 64 位服务器上,我希望我的应用程序读取 64 位数据源(存储在 reg key Software\Wow6432Node\ODBC\ODBC.INI\ODBC Data Sources 中),如果是 32 位,我想读取 32位数据源(即从 Software\ODBC\ODBC.INI\ODBC 数据源读取)。
我可能没有抓住重点,但我不想关心我的应用程序运行的模式。我只是想知道操作系统是 32 位还是 64 位。
[System.Environment.OSVersion.Platform 似乎并不适合我。它在我的本地 xp 机器和 win2k8 64 位服务器上返回 Win32NT(即使我的所有项目都设置为针对“任何 cpu”)]
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 projects are set to target 'any cpu')]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通常你甚至不应该担心这个。在 64 位平台上运行 32 位应用程序时,系统会自动将注册表查询重定向到
Software\Wow6432Node
。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.尝试使用属性
Environment.Is64BitOperatingSystem
。这是.Net 4.0中新增的一项,专门用于检查操作系统的类型。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:
您不应该直接阅读 Wow6432Node。使用 RegistryView作为 64 位应用程序运行时指定 32 位视图。
You should not read Wow6432Node directly. Use RegistryView to specify a 32-bit view when running as a 64-bit app.
如何使用.net检测Windows 64位平台? 可能会有所帮助。
How to detect Windows 64 bit platform with .net? might be helpful.