码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-01-17 14:08:58      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:detail   fine   tun   sizeof   return   好的   内容   pre   sys   

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

#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系统的版本号的代码

标签:detail   fine   tun   sizeof   return   好的   内容   pre   sys   

原文地址:http://blog.51cto.com/14101311/2343732

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!