如何获取有关计算机的信息? [32位或64位]
如何获取有关 Windows 操作系统类型的信息?是32位还是64位?我如何以编程方式获取此信息?
How I can get information about Windows OS type? Is it 32bit or 64bit? How I can get this information programatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您需要使用
GetProcAddress()
来检查IsWow64Process()
函数在运行时,如下所示:因为该函数仅在具有 64 位风格的 Windows 版本上可用。将其声明为
外部
会阻止您的应用程序在 Windows 2000 或 Windows XP SP2 之前的版本上运行。编辑:
Chris 发布了关于出于性能原因缓存结果的评论。对于这个特定的 API 函数来说,这可能不是必需的,因为 kernel32.dll 将始终存在(我无法想象没有它的程序会加载),但对于其他函数来说,事情可能是不同的。因此,这里有一个缓存函数结果的版本:
缓存此函数结果是安全的,因为 API 函数要么存在,要么不存在,并且其结果在同一 Windows 安装上无法更改。从多个线程同时调用此函数甚至是安全的,因为发现
WasCalled
为False
的两个线程都会调用该函数,将相同的结果写入相同的内存位置,然后才将WasCalled
设置为True
。You need to use
GetProcAddress()
to check the availability of theIsWow64Process()
function at runtime, like so:because that function is only available on Windows versions that do have a 64 bit flavour. Declaring it as
external
would prevent your application from running on Windows 2000 or Windows XP pre SP2.Edit:
Chris has posted a comment about caching the result for performance reasons. This may not be necessary for this particular API function, because kernel32.dll will always be there (and I can't imagine a program that would even load without it), but for other functions things may be different. So here's a version that caches the function result:
Caching this function result is safe, as the API function will either be there or not, and its result can't change on the same Windows installation. It is even safe to call this concurrently from multiple threads, as two threads finding
WasCalled
to beFalse
will both call the function, write the same result to the same memory location, and only afterwards setWasCalled
toTrue
.如果 a) 您使用的是 Windows,并且 b) 您可以访问注册表,则 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion 应该提供信息。
If a) you're on windows and b) you can access the registry then HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion should be informative.
除了
IsWow64Process
之外,您可能会对 GetNativeSystemInfo API 函数(它在Windows
单元中定义)感兴趣,以了解有关您所使用的 CPU 的更多信息(或者您可以使用程序集和CPUID )。
In addition to
IsWow64Process
, the GetNativeSystemInfo API function may be of interest to you (it's defined in theWindows
unit) to find out more about the CPU you're on (or you can use assembly andCPUID
).对于delphi XE+
示例
for delphi XE+
Example
我不知道如何在Delphi中调用Win32函数。
但如果你编写32位程序,你可以调用Win32 API IsWow64Process来知道你是否在64位操作系统中。
当然,如果你写的是64位的exe,那么它只能在64位Windows上运行,所以就不用问了。
I don't know how to call Win32 function in Delphi.
But if you write a 32-bit program, you can call the Win32 API IsWow64Process to know if you are in a 64-bit OS.
Of course, if you write a 64-bit exe, it will only run on 64-bit Windows, so there is no need to ask.
//尚未测试,但你可以尝试这个
//not tested but u can try this