作者:dfdzgf_542 | 来源:互联网 | 2023-05-19 07:37
获取的win8和win8.1都是6.2 那么该如何区分 而且wProductType==VER_NT_WORKSTATION
21 个解决方案
8.1 的版本号应该是 6.3 吧,不知道你是怎么获取的,难道是兼容模式?
http://msdn.microsoft.com/en-us/library/ms724832.aspx
个人不建议用 GetVersion 或 GetVersionEx 之类的 API 来获取系统版本号。注意微软也说过,这个结果会受到兼容模式的影响,即如果程序设置兼容模式为 XP 那么拿到的也可能使 5.1 的。所以要准确的获取版本号,我建议直接获取 kernel32.dll 的主版本号,这个是和系统的版本号是一样的。
现在应该用新API取代旧的GetVersion/ and GetVersionEx了
IsWindows8Point1OrGreater()
http://msdn.microsoft.com/en-us/library/windows/desktop/dn424972%28v=vs.85%29.aspx
回楼上,我试了一下在Win8.1下设置为Win7兼容模式,获取的还是8.1.应该没有问题吧。
填充以下数据
typedef struct _OSVERSIONINFO{
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[ 128 ];
} OSVERSIONINFO
分享一個我自己用於比較精確的系統版本判斷 C 代碼:
http://pan.baidu.com/s/1eQkykuQ
之所以叫比較精確,因為 Service Pack 可以通過兼容模式來偽造,因此只獲取系統名稱和位數。
Win8.1的确是6.3,通过DLL的方法还是靠谱的。
通过以下结构体返回你需要的各项数据
The OSVERSIONINFOEX structure contains operating system version information. The information includes major and minor version numbers, a build number, a platform identifier, and information about the latest Service Pack installed on the system. This structure is used with the GetVersionEx function. OSVERSIONINFOEX is an extended version of the OSVERSIONINFO structure.
typedef struct _OSVERSIONINFOEXA {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[ 128 ];
WORD wServicePackMajor;
WORD wServicePackMinor;
WORD wReserved[2];
} OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
Members
dwOSVersionInfoSize
Specifies the size, in bytes, of this data structure. Set this member to sizeof(OSVERSIONINFOEX) before calling the GetVersionEx function.
dwMajorVersion
Identifies the major version number of the operating system. For example, for Windows NT version 5.0, the major version number is 5.
dwMinorVersion
Identifies the minor version number of the operating system. For example, for Windows NT version 5.0, the minor version number is 0.
dwBuildNumber
Identifies the build number of the operating system.
dwPlatformId
Identifies the operating system platform. This member can be one of the following values. Value Platform
VER_PLATFORM_WIN32s Win32s on Windows 3.1.
VER_PLATFORM_WIN32_WINDOWS Win32 on Windows 95 or Windows 98.
VER_PLATFORM_WIN32_NT Win32 on Windows NT.
szCSDVersion
Contains a null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system. If no Service Pack has been installed, the string is empty.
wServicePackMajor
Identifies the major version number of the latest Service Pack installed on the system. If no Service Pack has been installed, the value is zero.
wServicePackMinor
Identifies the minor version number of the latest Service Pack installed on the system. If no Service Pack has been installed, the value is zero.
wReserved
Reserved for future use.
QuickInfo