本文共 1819 字,大约阅读时间需要 6 分钟。
在开发过程中中,把开发过程中比较好的内容片段备份一次,下边内容段是关于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
转载于:https://blog.51cto.com/14101311/2343732