如何确定我的应用程序是在x86还是x64 Windows上运行?

时间:2023-01-21 15:24:15

I want to know, at run time, whether I'm running on 32 bit or 64 bit windows. The OSVERSIONINFOEX structure tells me the major and minor version, but I'm guessing I need the build numbers. Anyone know what they are?

我想知道,在运行时,我是在32位还是64位窗口上运行。 OSVERSIONINFOEX结构告诉我主要和次要版本,但我猜我需要构建号码。谁知道它们是什么?

4 个解决方案

#1


If your application is compiled for 64-bit, then the answer's easy: you're running on 64-bit Windows.

如果您的应用程序是针对64位编译的,那么答案很简单:您在64位Windows上运行。

If your application is compiled for 32-bit, you need to call IsWow64Process. This function is only exported on Windows XP or later; if you want to support earlier versions of Windows, you'll need to use GetProcAddress to get a pointer to this function.

如果您的应用程序是针对32位编译的,则需要调用IsWow64Process。此功能仅在Windows XP或更高版本中导出;如果要支持早期版本的Windows,则需要使用GetProcAddress来获取指向此函数的指针。

#2


Assuming you're using C++, there's a very good OS detection class here.

假设您正在使用C ++,那么这里有一个非常好的操作系统检测类。

#3


You can get the build number already from the OSVERSIONINFOEX structure.

您可以从OSVERSIONINFOEX结构获取内部版本号。

If you are a 32-bit process and want to know if you're running under WOW64 (ie., a 64-bit OS), call IsWow64Process(). (requires XP SP2 or later)

如果您是32位进程并想知道您是否在WOW64(即64位操作系统)下运行,请调用IsWow64Process()。 (需要XP SP2或更高版本)

#4


I use WMI.

我使用WMI。

select * from Win32_OperatingSystem

从Win32_OperatingSystem中选择*

Get the first instance, and then select the Version attribute. For WinXP, it returns 5.1.2600.

获取第一个实例,然后选择Version属性。对于WinXP,它返回5.1.2600。

#1


If your application is compiled for 64-bit, then the answer's easy: you're running on 64-bit Windows.

如果您的应用程序是针对64位编译的,那么答案很简单:您在64位Windows上运行。

If your application is compiled for 32-bit, you need to call IsWow64Process. This function is only exported on Windows XP or later; if you want to support earlier versions of Windows, you'll need to use GetProcAddress to get a pointer to this function.

如果您的应用程序是针对32位编译的,则需要调用IsWow64Process。此功能仅在Windows XP或更高版本中导出;如果要支持早期版本的Windows,则需要使用GetProcAddress来获取指向此函数的指针。

#2


Assuming you're using C++, there's a very good OS detection class here.

假设您正在使用C ++,那么这里有一个非常好的操作系统检测类。

#3


You can get the build number already from the OSVERSIONINFOEX structure.

您可以从OSVERSIONINFOEX结构获取内部版本号。

If you are a 32-bit process and want to know if you're running under WOW64 (ie., a 64-bit OS), call IsWow64Process(). (requires XP SP2 or later)

如果您是32位进程并想知道您是否在WOW64(即64位操作系统)下运行,请调用IsWow64Process()。 (需要XP SP2或更高版本)

#4


I use WMI.

我使用WMI。

select * from Win32_OperatingSystem

从Win32_OperatingSystem中选择*

Get the first instance, and then select the Version attribute. For WinXP, it returns 5.1.2600.

获取第一个实例,然后选择Version属性。对于WinXP,它返回5.1.2600。