在驅(qū)動中取得windows的詳細版本號

字號:

typedef enum WIN_VER_DETAIL {
    WINDOWS_VERSION_NONE, // 0
    WINDOWS_VERSION_2K,
    WINDOWS_VERSION_XP,
    WINDOWS_VERSION_2K3,
    WINDOWS_VERSION_2K3_SP1_SP2,
    WINDOWS_VERSION_VISTA,
    } WIN_VER_DETAIL;
    EXTERN_C WIN_VER_DETAIL GetWindowsVersion()
    {
    UNICODE_STRING ustrFuncName = { 0 };
    RTL_OSVERSIONINFOEXW osverinfo = { sizeof(osverinfo) };
    PFN_RtlGetVersion pfnRtlGetVersion = NULL;
    RtlInitUnicodeString(&ustrFuncName, L"RtlGetVersion");
    pfnRtlGetVersion = MmGetSystemRoutineAddress(&ustrFuncName);
    if (pfnRtlGetVersion)
    {
    kdprintf("[sgblkrmt] Using \"RtlGetVersion\"\n");
    pfnRtlGetVersion((PRTL_OSVERSIONINFOW)&osverinfo);
    }
    else
    {
    kdprintf("[sgblkrmt] Using \"PsGetVersion\"\n");
    PsGetVersion(&osverinfo.dwMajorVersion, &osverinfo.dwMinorVersion, &osverinfo.dwBuildNumber, NULL);
    }
    kdprintf("[sgblkrmt] OSVersion NT %d.%d:%d sp%d.%d\n",
    osverinfo.dwMajorVersion, osverinfo.dwMinorVersion, osverinfo.dwBuildNumber,
    osverinfo.wServicePackMajor, osverinfo.wServicePackMinor);
    if (osverinfo.dwMajorVersion == 5 && osverinfo.dwMinorVersion == 0) {
    return WINDOWS_VERSION_2K;
    } else if (osverinfo.dwMajorVersion == 5 && osverinfo.dwMinorVersion == 1) {
    return WINDOWS_VERSION_XP;
    } else if (osverinfo.dwMajorVersion == 5 && osverinfo.dwMinorVersion == 2) {
    if (osverinfo.wServicePackMajor==0) {
    return WINDOWS_VERSION_2K3;
    } else {
    return WINDOWS_VERSION_2K3_SP1_SP2;
    }
    } else if (osverinfo.dwMajorVersion == 6 && osverinfo.dwMinorVersion == 0) {
    return WINDOWS_VERSION_VISTA;
    }
    return WINDOWS_VERSION_NONE;
    }