C++获得当前windows系统的版本号的代码

在开发过程中中,把开发过程中比较好的内容片段备份一次,下边内容段是关于C++获得当前windows系统的版本号的内容,应该能对码农们也有好处。

创新互联公司长期为上1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为萧山企业提供专业的网站建设、网站制作萧山网站改版等技术服务。拥有十余年丰富建站经验和众多成功案例,为您定制开发。

#include "InitWindowsVersion.h"

      无
 WIN_VER_DETAIL GetWindowsVersion()
{
    UNICODE_STRING ustrFuncName = { 0 }; 
    RTL_OSVERSIONINFOEXW osverinfo = { sizeof(osverinfo) }; 
    PFN_RtlGetVersion pfnRtlGetVersion = NULL;

    if (WinVersion)
        return WinVersion;

    RtlInitUnicodeString(&ustrFuncName, L"RtlGetVersion"); 

    if (pfnRtlGetVersion)
    { 
        pfnRtlGetVersion((PRTL_OSVERSIONINFOW)&osverinfo); 
    } 
    else 
    {

        PsGetVersion(&osverinfo.dwMajorVersion, &osverinfo.dwMinorVersion, &osverinfo.dwBuildNumber, NULL);
    }

    if (osverinfo.dwMajorVersion == 5 && osverinfo.dwMinorVersion == 0) 
    {
        WinVersion = WINDOWS_VERSION_2K;
    } 
    else if (osverinfo.dwMajorVersion == 5 && osverinfo.dwMinorVersion == 1) 
    {
        WinVersion = WINDOWS_VERSION_XP;
    } 
    else if (osverinfo.dwMajorVersion == 5 && osverinfo.dwMinorVersion == 2) 
    {
        if (osverinfo.wServicePackMajor==0) 
        { 
            WinVersion = WINDOWS_VERSION_2K3;
        } 
        else 
        {
            WinVersion = WINDOWS_VERSION_2K3_SP1_SP2;
        }
    } 
    else if (osverinfo.dwMajorVersion == 6 && osverinfo.dwMinorVersion == 0) 
    {
        WinVersion = WINDOWS_VERSION_2K3_SP1_SP2;
    }
    else if (osverinfo.dwMajorVersion == 6 && osverinfo.dwMinorVersion == 1)
    {
        WinVersion = WINDOWS_VERSION_7;
    }

    return WinVersion;
}

InitWindowsVersion.h

#ifndef _SYSTEM_H
#define _SYSTEM_H

#include "ntifs.h"

typedef enum WIN_VER_DETAIL {
    WINDOWS_VERSION_2K,
    WINDOWS_VERSION_XP,
    WINDOWS_VERSION_2K3,
    WINDOWS_VERSION_2K3_SP1_SP2,
    WINDOWS_VERSION_VISTA_2008,
    WINDOWS_VERSION_7
} WIN_VER_DETAIL;

WIN_VER_DETAIL WinVersion;

 WIN_VER_DETAIL GetWindowsVersion();
#endif

分享名称:C++获得当前windows系统的版本号的代码
网址分享:http://myzitong.com/article/iipshp.html