【Windows】Windows中判断版本号【redis优秀案例】

cpp 复制代码
#include <Windows.h>

bool IsWindowsVersionAtLeast(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor);

bool IsWindowsVersionAtLeast(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor) {
    OSVERSIONINFOEXW osvi = {sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0};
    DWORDLONG const dwlConditionMask = VerSetConditionMask(
        VerSetConditionMask(
        VerSetConditionMask(
        0, VER_MAJORVERSION, VER_GREATER_EQUAL),
        VER_MINORVERSION, VER_GREATER_EQUAL),
        VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);

    osvi.dwMajorVersion = wMajorVersion;
    osvi.dwMinorVersion = wMinorVersion;
    osvi.wServicePackMajor = wServicePackMajor;

    return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
}


class WindowsVersion {
private:
    bool isAtLeast_6_0;/* 一般windows7, 如:6.1.6701 */
    bool isAtLeast_6_2;/* 一般windows8, 如:6.2.6900 */
	/* 可以继续添加期望判断的版本, windows10: 10.0.19045 */

    WindowsVersion() {
        isAtLeast_6_0 = IsWindowsVersionAtLeast(6, 0, 0);
        isAtLeast_6_2 = IsWindowsVersionAtLeast(6, 2, 0);
    }

    WindowsVersion(WindowsVersion const&);      // Don't implement to guarantee singleton semantics
    void operator=(WindowsVersion const&);      // Don't implement to guarantee singleton semantics

public:
    static WindowsVersion& getInstance() {
        static WindowsVersion instance;         // Instantiated on first use. Guaranteed to be destroyed.
        return instance;
    }

    bool IsAtLeast_6_0() {
        return isAtLeast_6_0;
    }

    bool IsAtLeast_6_2() {
        return isAtLeast_6_2;
    }
};

在 Windows 上,可以使用以下方法之一来查看操作系统的版本号:

  1. 使用 "winver" 命令:

    • 打开 "运行" 对话框,可以通过按下 Win + R 快捷键来打开。
    • 在对话框中输入 "winver",然后点击 "确定"。
    • 弹出的 "关于 Windows" 窗口中,会显示操作系统的版本号和详细信息。
  2. 使用 "系统信息" 工具:

    • 打开 "运行" 对话框。
    • 输入 "msinfo32",然后点击 "确定"。
    • 打开的 "系统信息" 窗口中,可以在 "操作系统名称" 和 "版本" 字段中找到操作系统的版本号。
  3. 使用 "命令提示符" 或 "PowerShell":

    • 打开 "命令提示符" 或 "PowerShell"。

    • 输入以下命令并按下回车:

      复制代码
      systeminfo | findstr /B /C:"OS 名称" /C:"OS 版本"
    • 输出中的 "OS 名称" 和 "OS 版本" 行将显示操作系统的名称和版本号。

这些方法可以帮助您在 Windows 上方便地查看操作系统的版本号。

相关推荐
有梦想的攻城狮2 分钟前
Java 11中的Collections类详解
java·windows·python·java11·collections
忒可君8 分钟前
C# winform FTP功能
开发语言·windows·c#
十五年专注C++开发1 小时前
CMake进阶: CMake Modules---简化CMake配置的利器
linux·c++·windows·cmake·自动化构建
degree5201 小时前
全平台轻量浏览器推荐|支持Win/macOS/Linux,极速加载+隐私保护+扩展插件,告别广告与数据追踪!
windows·macos·电脑
许泽宇的技术分享1 天前
Windows桌面自动化的革命性突破:深度解析Windows-MCP.Net Desktop模块的技术奥秘
windows·自动化·.net
七仔的博客1 天前
【摸鱼办公神器】七仔的桌面工具超进化 -> 灵卡面板 v1.1.9
windows·神器·摸鱼
码农阿豪1 天前
Windows从零到一安装KingbaseES数据库及使用ksql工具连接全指南
数据库·windows
CC__xy2 天前
demo 通讯录 + 城市选择器 (字母索引左右联动 ListItemGroup+AlphabetIndexer)笔记
windows
LZQqqqqo2 天前
C# 中 ArrayList动态数组、List<T>列表与 Dictionary<T Key, T Value>字典的深度对比
windows·c#·list
季春二九2 天前
Windows 11 首次开机引导(OOBE 阶段)跳过登录微软账户,创建本地账户
windows·microsoft