【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 上方便地查看操作系统的版本号。

相关推荐
2601_9583205732 分钟前
【小白零基础上手 】钉钉内部机器人接入 OpenClaw 完整流程讲解(含安装包)
人工智能·windows·机器人·钉钉·open claw·open claw安装
love530love1 小时前
f2 项目(多平台的作品下载与接口数据处理)源码部署记录
人工智能·windows·f2
生而为虫1 小时前
在VScode中使用Claude Code agent并配置模型(仅mac电脑实际操作,windows电脑未实际操作如有问题可留言)
windows·vscode·macos
叶小鸡2 小时前
Java 篇-项目实战-天机学堂(从0到1)-day10
windows·microsoft
love530love2 小时前
如何在 Google Chrome 中强制开启 Gemini AI 侧边栏(完整图文教程)
前端·人工智能·chrome·windows
skilllite作者2 小时前
Zed 1.0 编辑器深度评测与实战指南
开发语言·人工智能·windows·python·编辑器·agi
杜哥无敌2 小时前
FreeSSHd vs FileZilla Server vs SFTPGo:Windows SFTP服务器易用性终极横向测评
运维·服务器·windows
李白的天不白2 小时前
vue 数据格式问题
前端·vue.js·windows
love530love14 小时前
精简版|Claude-HUD 插件介绍 + 一键安装教程
人工智能·windows·笔记
秋915 小时前
MySQL 8.0.46 全平台安装与配置详解(Windows/Linux/macOS)
linux·windows·mysql