溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C++獲得當前windows系統(tǒng)的版本號的代碼

發(fā)布時間:2020-08-03 07:16:09 來源:網(wǎng)絡 閱讀:856 作者:Cool_Manone 欄目:編程語言

在開發(fā)過程中中,把開發(fā)過程中比較好的內(nèi)容片段備份一次,下邊內(nèi)容段是關于C++獲得當前windows系統(tǒng)的版本號的內(nèi)容,應該能對碼農(nóng)們也有好處。

#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
向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI