如何检测32/64平台?

问题描述:

我需要检测应用程序是否在 Win32/64 上运行.

I need to detect if the app is running on Win32/64.

更新:人员报告说依赖 [HKLMHARDWAREDESCRIPTIONSystemCentralProcessor ] 键不是一个好主意.

Update: People are reporting that relying on the [HKLMHARDWAREDESCRIPTIONSystemCentralProcessor ] key is not a good idea.

您在问题中提供的代码有一些问题,但它确实可以正常工作.我怀疑您实际上并没有运行该代码,并且犯了错误并以某种方式发布了错误的代码.

The code that you present in the question has a few wrinkles, but it does work correctly. I suspect that you are not actually running that code, and have made an error and somehow posted the wrong code.

FWIW,您应该使用 中的 TOSVersionSystem.SysUtils 用于检查底层平台的位数.TOSVersion.Architecture 属性会告诉您是否底层平台为32位或64位.

FWIW, you should use TOSVersion from System.SysUtils to check the bitness of the underlying platform. The TOSVersion.Architecture property will tell you whether or not the underlying platform is 32 or 64 bit.