利用未文档化API:RtlGetNtVersionNumbers 获取系统版本号

时间:2021-09-16 01:13:45

问题一:Windows SDK 8.1版本中的VersionHelper.h文件当中没有IsWindows10ORGreater,所以当你用IsWindows8Point1ORGreater判断出版本信息是Windows8.1以上的版本后,你就无法区分它到底是Win8.1还是Win10.

问题二:使用GetVersionEx这个API配合结构体OSVERSIONINFOEX这个方法获取版本信息,那么Win8以上的系统不论是Win8.1还是Win10都会被判定为主版本号为6,次版本号为2(即Win8的版本号)。

参考:

http://blog.csdn.net/pjl1119/article/details/8556693

和MSDN相关API说明。

那么如何区分Win8.1和Win10?

使用如下未文档化API:

RtlGetNtVersionNumbers

参考:

http://blog.csdn.net/magictong/article/details/40753519

使用方法如下:

int main()
{
HMODULE hm;
if (hm = LoadLibrary("ntdll.dll"))
{
DWORD i = , j = , p = ;
typedef void (WINAPI *getver)(DWORD*, DWORD*, DWORD*);
getver gv;
gv = (getver)GetProcAddress(hm, "RtlGetNtVersionNumbers");
if (gv)
{
gv(&i, &j, &p);
printf("Major is %d\nMinor is %d\nOptional Build is %d\n", i, j, p); } FreeLibrary(hm);
}
system("pause");
return ;
}

Windows7下返回结果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPwAAABHCAIAAACsxL2GAAAKeklEQVR4nO2d+VcayRbH+T8Stm5oGlAzOXPmzJu/6kUniSaKCCqI+5bE5GXejArKIqgxmmhEm6VB3LLMvP/n/cAidFffrkZElPs5dTxN9a3vvVV8qw4BJTrf9JvhiYUh/8zhcUbMn2bzpxmxkBZP0tl8Sqllcootm09l8+mqlhFPyq2QzRWyxZ+klqk0sZART9Kllk+Lxbw5ISMep8WjVPYolT0SMkkhkzxOHx6lvlS1g6RwkBQOksf7h8f7h0f7h0efvxRb8vOX5KeD5KeDw739w939w93Ph7vFi/3kx/3kx4Pkxy9HO8WWPN4Rjj+kUzti6kMu9SGX2s6ltnOpLfF4K5VMJL8k9j/H9z4ldj8lPn5K7OwlPuzFt/fi27sb27sbW7sbW7s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hkgbmnmwooRPbF0k2NesqO1JPii181Jk8wAa3M4B4NuBZgDwAc0A4AN5zQD4gGYA8AHNAODjNzVz1adlH6H8lBIQ9loA4Wb5bfkDzVxNlh+sd7obm2bIo9u7ywaaAfWkmmHJjJPyuzFKAZ6WPOiuD5HqZ+Z2JvU2St5U3jgtmZGedUvVCxb7ydP+JP3KNZ+LGRSyHbl/Mu1REkOVfs7m6Sn+cEeKmtl7gSUqxQlhcmHKjvdBTyfXzxD/jmwSL7acixQIsbx44brc9oM8rid2iu4l52tpdrT+0doTmUs0o/WzqBnNH+6JHJvJI/jWSbT/WadKHXYoWZfmO6v5abKrZEz2SaPU6/LaT2wlBpVdykZydgrzgEszWr65klOr9NstEe4BsIgqvXxhspfyOoWyKnNIwk5RrnuJZg5DbLAGEkKdh3JdPvu8dfKmonMpO1TUIzXVTNYfbogQm0UYvzSJI1OOMr0ZfMLo0v36y27Z2izhELNkTplnlPDt4vPM7anSjClmPbC20epncj4xO9g0maICOkQWSkgq7AfZ38m2cimKOsBodnL9k1k+mTWj1h1VrWHmyd5+WOv9zdRpRgnntDoQf32IXj+jasazaIoPnRuX3klKOty7KItMFeqIjFaU0hTaz4X+yXxfdLtsJ46wyZyb6TeNq2jmpaAecKM8gNZrz9uvbX+U39WM6dbthe2DT/GLmlnDglZzQGv74LP8omYA+FOgGQB8QDMA+IBmAPABzQDgA5oBwAc0A4CL//P3BEhbfI75AAAAAElFTkSuQmCC" alt="" />

这样我们即使不是用WindowsSDK10,也能区分开Win8.1和Win10了。

其他方法:

http://blog.csdn.net/k1988/article/details/47614529

其中这篇文章分析了很多方法:

http://blog.csdn.net/magictong/article/details/40753519