GetVersionEx 如何区分win8和win8.1

qw_stone 2014-12-10 10:22:11
获取的win8和win8.1都是6.2 那么该如何区分 而且wProductType==VER_NT_WORKSTATION
...全文
2460 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
dragoo1 2018-10-11
  • 打赏
  • 举报
回复
引用 19 楼 SXJIAKE 的回复:
[quote=引用 18 楼 yayexing 的回复:]
[quote=引用 15 楼 SXJIAKE 的回复:]
分享一個我自己用於比較精確的系統版本判斷 C 代碼:
http://pan.baidu.com/s/1eQkykuQ
之所以叫比較精確,因為 Service Pack 可以通過兼容模式來偽造,因此只獲取系統名稱和位數。

这位大神,我现在也在想要这方面的资料,你提供的链接已经没有了,能在提供一个吗。[/quote]
#include <windows.h>
// 所需头和库
#include <lm.h>
#pragma comment(lib, "netapi32.lib")
// 获取版本号
WKSTA_INFO_100 *wkstaInfo = NULL;
NET_API_STATUS netStatus = NetWkstaGetInfo(NULL, 100, (LPBYTE *)&wkstaInfo);
if (netStatus == NERR_Success) {
DWORD dwMajVer = wkstaInfo->wki100_ver_major;
DWORD dwMinVer = wkstaInfo->wki100_ver_minor;
DWORD dwVersion = (DWORD)MAKELONG(dwMinVer, dwMajVer);
netStatus = NetApiBufferFree(wkstaInfo);
}
此方法可以获取到准确的版本号,不依赖于 manifest 文件,也不受兼容性的影响。[/quote]
谢谢分享,学习了
yayexing 2015-12-11
  • 打赏
  • 举报
回复
引用 19 楼 SXJIAKE 的回复:
[quote=引用 18 楼 yayexing 的回复:] [quote=引用 15 楼 SXJIAKE 的回复:] 分享一個我自己用於比較精確的系統版本判斷 C 代碼: http://pan.baidu.com/s/1eQkykuQ 之所以叫比較精確,因為 Service Pack 可以通過兼容模式來偽造,因此只獲取系統名稱和位數。
这位大神,我现在也在想要这方面的资料,你提供的链接已经没有了,能在提供一个吗。[/quote]
#include <windows.h>
// 所需头和库
#include <lm.h>
#pragma comment(lib, "netapi32.lib")
// 获取版本号
WKSTA_INFO_100 *wkstaInfo = NULL;
NET_API_STATUS netStatus = NetWkstaGetInfo(NULL, 100, (LPBYTE *)&wkstaInfo);
if (netStatus == NERR_Success) {
    DWORD dwMajVer = wkstaInfo->wki100_ver_major;
    DWORD dwMinVer = wkstaInfo->wki100_ver_minor;
    DWORD dwVersion = (DWORD)MAKELONG(dwMinVer, dwMajVer);
    netStatus = NetApiBufferFree(wkstaInfo);
}
此方法可以获取到准确的版本号,不依赖于 manifest 文件,也不受兼容性的影响。[/quote] 小弟受教了,此方法确实可以获取到版本号和副版本号,我前面用您之前提供的获取kernel32.dll的版本信息,在win10下面取到的大版本号也是6.2,后面dll的编译号却是不受影响,唉,好久没在csdn里面取到这么有分享精神的大神了,太感谢了。
worldy 2015-12-10
  • 打赏
  • 举报
回复
通过以下结构体返回你需要的各项数据 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
「已注销」 2015-12-10
  • 打赏
  • 举报
回复
引用 18 楼 yayexing 的回复:
[quote=引用 15 楼 SXJIAKE 的回复:] 分享一個我自己用於比較精確的系統版本判斷 C 代碼: http://pan.baidu.com/s/1eQkykuQ 之所以叫比較精確,因為 Service Pack 可以通過兼容模式來偽造,因此只獲取系統名稱和位數。
这位大神,我现在也在想要这方面的资料,你提供的链接已经没有了,能在提供一个吗。[/quote]
#include <windows.h>
// 所需头和库
#include <lm.h>
#pragma comment(lib, "netapi32.lib")
// 获取版本号
WKSTA_INFO_100 *wkstaInfo = NULL;
NET_API_STATUS netStatus = NetWkstaGetInfo(NULL, 100, (LPBYTE *)&wkstaInfo);
if (netStatus == NERR_Success) {
    DWORD dwMajVer = wkstaInfo->wki100_ver_major;
    DWORD dwMinVer = wkstaInfo->wki100_ver_minor;
    DWORD dwVersion = (DWORD)MAKELONG(dwMinVer, dwMajVer);
    netStatus = NetApiBufferFree(wkstaInfo);
}
此方法可以获取到准确的版本号,不依赖于 manifest 文件,也不受兼容性的影响。
yayexing 2015-12-10
  • 打赏
  • 举报
回复
引用 15 楼 SXJIAKE 的回复:
分享一個我自己用於比較精確的系統版本判斷 C 代碼: http://pan.baidu.com/s/1eQkykuQ 之所以叫比較精確,因為 Service Pack 可以通過兼容模式來偽造,因此只獲取系統名稱和位數。
这位大神,我现在也在想要这方面的资料,你提供的链接已经没有了,能在提供一个吗。
至天 2015-05-25
  • 打赏
  • 举报
回复
Win8.1的确是6.3,通过DLL的方法还是靠谱的。
「已注销」 2015-04-27
  • 打赏
  • 举报
回复
引用 13 楼 CIPORE 的回复:
只能获得主版本号吗?如果具体区分是不还应该增加获得副信息号功能?
目前覺得,取得 kernel32.dll 得到系統的準確主版本號,配合 GetSystemInfo (GetNativeSysteminfo) 和 GetVersionEx 還是可以用的,傳一個 OSVERSIONINFOEX 結構體,可以通過其中除了系統版本號、Service Pack 版本等這些容易收到兼容性影響而得到錯誤結果之外的其他值來確定大致版本號。 排除 SP,如何精確判斷系統,可參考此頁: https://msdn.microsoft.com/en-us/library/ms724833.aspx 其中 Remarks 段有具體說明。 如果要在兼容性模式下獲取精確 Service Pack 可能就不好辦了,畢竟兼容性裡面有 XP SP2 和 XP SP3,因此 OSVERSIONINFOEX 的 szCSDVersion、wServicePackMajor、wServicePackMinor 的結果也可能也不準確。但是畢竟兼容性設置再強悍也不可能把個人系統“兼容”為服務器系統吧,也不會把32位“兼容”為64位吧。比如 OSVERSIONINFOEX.wProductType 這個參數,應該是不會受兼容性影響。
「已注销」 2015-04-27
  • 打赏
  • 举报
回复
引用 13 楼 CIPORE 的回复:
只能获得主版本号吗?如果具体区分是不还应该增加获得副信息号功能?
忘了說明了,dwFileVersionMS 得到的其實是類似 6.2、6.3 這樣的。你具體看我的例子吧。
「已注销」 2015-04-27
  • 打赏
  • 举报
回复
分享一個我自己用於比較精確的系統版本判斷 C 代碼: http://pan.baidu.com/s/1eQkykuQ 之所以叫比較精確,因為 Service Pack 可以通過兼容模式來偽造,因此只獲取系統名稱和位數。
CIPORE 2015-04-24
  • 打赏
  • 举报
回复
引用 2 楼 SXJIAKE 的回复:
DWORD GetKernelMajorVerion(void)
{
    DWORD dwVersion = MAKELONG(0, 0);
    WCHAR szDLLName[MAX_PATH] = { 0 };
    HRESULT hr = SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, SHGFP_TYPE_CURRENT, szDLLName);
    if (SUCCEEDED(hr) && PathAppendW(szDLLName, L"kernel32.dll")) {
        DWORD dwVerInfoSize = GetFileVersionInfoSizeW(szDLLName, NULL);
        if (dwVerInfoSize > 0) {
            LPVOID pvVerInfoData = (LPVOID)new BYTE[dwVerInfoSize];
            if (GetFileVersionInfoW(szDLLName, 0, dwVerInfoSize, pvVerInfoData)) {
                UINT ulLength = 0;
                VS_FIXEDFILEINFO *pvffi = NULL;
                if (VerQueryValueW(pvVerInfoData, L"\\", (LPVOID *)&pvffi, &ulLength)) {
                    dwVersion = pvffi->dwFileVersionMS;
                }
            }
            delete[] pvVerInfoData;
        }
    }
    return dwVersion;
}
只能获得主版本号吗?如果具体区分是不还应该增加获得副信息号功能?
worldy 2015-03-01
  • 打赏
  • 举报
回复
填充以下数据 typedef struct _OSVERSIONINFO{ DWORD dwOSVersionInfoSize; DWORD dwMajorVersion; DWORD dwMinorVersion; DWORD dwBuildNumber; DWORD dwPlatformId; TCHAR szCSDVersion[ 128 ]; } OSVERSIONINFO
Fish_Tif 2015-03-01
  • 打赏
  • 举报
回复
可以用ntdll中的RtlGetNtVersionNumbers
typedef void (__stdcall*NTPROC)(DWORD*,DWORD*,DWORD*);
void GetWinVer()
{
HINSTANCE hinst = LoadLibrary("ntdll.dll");
DWORD dwMajor,dwMinor,dwBuildNumber;
NTPROC proc = (NTPROC)GetProcAddress(hinst,"RtlGetNtVersionNumbers");
proc(&dwMajor,&dwMinor,&dwBuildNumber);
dwBuildNumber&=0xffff;
}
这是一个undocumented API
「已注销」 2014-12-17
  • 打赏
  • 举报
回复
还真没了解过,没有真正测试过在 8.1 上获取的版本号也是 6.1。 这是我现在常用的一个 manifest 配置,让 C 风格程序使用主题:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <dependency>
        <dependentAssembly>
            <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" />
        </dependentAssembly>
    </dependency>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
            <!-- This Id value indicates the application supports Windows Vista functionality -->
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> 
            <!-- This Id value indicates the application supports Windows 7 functionality -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
            <!-- This Id value indicates the application supports Windows 8 functionality -->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
            <!-- This Id value indicates the application supports Windows 8.1 functionality -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
        </application>
    </compatibility>
</assembly>
  • 打赏
  • 举报
回复
引用 8 楼 SXJIAKE 的回复:
还真没了解过,没有真正测试过在 8.1 上获取的版本号也是 6.1。 这是我现在常用的一个 manifest 配置,让 C 风格程序使用主题:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <dependency>
        <dependentAssembly>
            <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" />
        </dependentAssembly>
    </dependency>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
            <!-- This Id value indicates the application supports Windows Vista functionality -->
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> 
            <!-- This Id value indicates the application supports Windows 7 functionality -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
            <!-- This Id value indicates the application supports Windows 8 functionality -->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
            <!-- This Id value indicates the application supports Windows 8.1 functionality -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
        </application>
    </compatibility>
</assembly>
6.1是win7,win8和win8.1不会获取到6.1,至少也是6.2
dvlinker 2014-12-17
  • 打赏
  • 举报
回复
这个没试过,帮忙顶一下!
  • 打赏
  • 举报
回复
引用 6 楼 my3439955 的回复:
对于一个未加特殊处理的应用程序用GetVersionEx获取win8和win8.1系统版本,一律都是6.2 这是微软的兼容性考虑 如果你的程序是专门为Win8.1准备的,那么可以主动说明,这时候获得的版本是6.2和6.3 Win8.1的版本实际上是6.3 如何主动说明呢?加manifest,核心内容如下: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> </application> </compatibility> </assembly>
传个代码说明一下 http://download.csdn.net/detail/my3439955/8267571
  • 打赏
  • 举报
回复
对于一个未加特殊处理的应用程序用GetVersionEx获取win8和win8.1系统版本,一律都是6.2 这是微软的兼容性考虑 如果你的程序是专门为Win8.1准备的,那么可以主动说明,这时候获得的版本是6.2和6.3 Win8.1的版本实际上是6.3 如何主动说明呢?加manifest,核心内容如下: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> </application> </compatibility> </assembly>
nokia007 2014-12-16
  • 打赏
  • 举报
回复
回楼上,我试了一下在Win8.1下设置为Win7兼容模式,获取的还是8.1.应该没有问题吧。
「已注销」 2014-12-15
  • 打赏
  • 举报
回复
引用 3 楼 nokia007 的回复:
现在应该用新API取代旧的GetVersion/ and GetVersionEx了 IsWindows8Point1OrGreater() http://msdn.microsoft.com/en-us/library/windows/desktop/dn424972%28v=vs.85%29.aspx
这个并非系统 API,而是由头文件 versionhelpers.h 提供的,其中有具体的实现,它是通过 VerifyVersionInfo 函数实现的,这个函数会受到兼容性设置的影响。系统中所有获取系统版本号的函数都会受到兼容性设置的影响,唯有获取 kernel32.dll 的版本号是最保险的。
nokia007 2014-12-12
  • 打赏
  • 举报
回复
现在应该用新API取代旧的GetVersion/ and GetVersionEx了 IsWindows8Point1OrGreater() http://msdn.microsoft.com/en-us/library/windows/desktop/dn424972%28v=vs.85%29.aspx
加载更多回复(2)

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧