程序如何在vista下知道自己是在vista上运行?

来源:百度知道 编辑:UC知道 时间:2024/07/05 17:58:08
vista有时候会自动把程序运行在兼容模式下,此时GetVersion返回的是兼容模式的虚假版本号。
程序如何知道自己是否在vista上运行?

或者能避免程序运行在兼容模式下也行。
GetVersionEx确定有用吗?GetVersion反正是取到伪造的值,没道理GetVersionEx能取到真实值啊。

另外补充下我新发现的一个办法:观察注册表HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\下BuildLab的值。这个值在vista运行兼容模式时不会被伪造成XP的值。(ProductName等的都会被伪造成XP的值)
理论上这个方式还是不保险,没准就被DIYer狂人改了。有更好的办法再提提。

gz

使用 GetVersionEx 函数

#include <windows.h>
#include <stdio.h>

#define BUFSIZE 80

int main()
{
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;

// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
// If that fails, try using the OSVERSIONINFO structure.

ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
{
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
return FALSE;
}

switch (osvi.dwPlatformId)
{
// Test for the Windows NT product family.
case VER_PLATFORM_WIN32_NT:

// Test for the specific product.
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )