如何获取 Windows 11 的操作系统版本信息

发布于 2025-01-09 16:15:05 字数 729 浏览 1 评论 0原文

GetVersionEx Api 可以用 C++ 获得 Windows10 版本。

#include <windows.h>
#include <stdio.h>

void main()
{
    OSVERSIONINFO osvi;    
    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

    GetVersionEx(&osvi);
}

版本帮助程序函数有一个 IsWindows10OrGreater api,可以检查它是 Windows10 或更高版本,但我需要 Windows11 的版本信息。有没有像 GetVersionEx 这样的 Api 我可以从那里获取 Windows11 的完整版本信息。

The GetVersionEx Api can get version upto Windows10 in C++.

#include <windows.h>
#include <stdio.h>

void main()
{
    OSVERSIONINFO osvi;    
    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

    GetVersionEx(&osvi);
}

Version Helper functions have an IsWindows10OrGreater api that can check it's Windows10 or greater but i need exactly the version info of Windows11. Is there any Api like GetVersionEx from there i can get the whole version info of Windows11.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老旧海报 2025-01-16 16:15:05
 typedef struct _OSVERSIONINFO{
    DWORD dwOSVersionInfoSize;
    DWORD dwMajorVersion;
    DWORD dwMinorVersion;
    DWORD dwBuildNumber;
    DWORD dwPlatformId;
    TCHAR szCSDVersion[ 128 ];
 } OSVERSIONINFO;

为什么不使用 dwBuildNumber 来识别 Windows 11 版本? Windows 11 内部版本号从 22000 开始,您可以在线搜索所需的确切内部版本号。

 typedef struct _OSVERSIONINFO{
    DWORD dwOSVersionInfoSize;
    DWORD dwMajorVersion;
    DWORD dwMinorVersion;
    DWORD dwBuildNumber;
    DWORD dwPlatformId;
    TCHAR szCSDVersion[ 128 ];
 } OSVERSIONINFO;

Why don't you use the dwBuildNumber for identifying the Windows 11 Version? Windows 11 build number starts from 22000, and you can search up online the exact build number you are looking for.

扭转时空 2025-01-16 16:15:05

直接(但不推荐):GetVersionGetVersionEx 均已弃用。也就是说,如果您确实想检测 Windows 11,则可以使用 GetVersionEx 返回的 OSVERSIONINFOEXdwBuildNumber 成员。 “https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information” rel="nofollow noreferrer">Windows 11 发布信息页面, dwBuildNumber 的值 22000 及以上将指示 Windows 11。

推荐方式: 引用此页面:https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version

识别当前操作系统通常不是确定特定操作系统功能是否存在的最佳方法。这是因为操作系统可能在可再发行 DLL 中添加了新功能。不要使用版本 API 帮助程序函数来确定操作系统平台或版本号,而是测试该功能本身是否存在。

要确定测试功能的最佳方法,请参阅感兴趣功能的文档。以下列表讨论了一些常见的特征检测技术:

您可以测试与某项功能关联的功能是否存在。要测试系统 DLL 中是否存在函数,请调用 LoadLibrary 函数来加载 DLL。然后调用 GetProcAddress 函数来确定 DLL 中是否存在感兴趣的函数。使用 GetProcAddress 返回的指针来调用该函数。请注意,即使该函数存在,它也可能是一个仅返回错误代码(例如 ERROR_CALL_NOT_IMPLMENTED)的存根。
您可以使用 GetSystemMetrics 函数确定某些功能是否存在。例如,您可以通过调用 GetSystemMetrics(SM_CMONITORS) 来检测多个显示监视器。
有多个版本的可再发行 DLL 实现了 shell 和通用控制功能。有关确定运行应用程序的系统上存在哪些版本的信息,请参阅主题 Shell 和通用控件版本。
如果您必须需要特定的操作系统,请务必将其用作受支持的最低版本,而不是为一个操作系统设计测试。这样,您的检测代码将继续在未来版本的 Windows 上运行。

Direct (but not recommended way): Both GetVersion and GetVersionEx are deprecated. That said, you can use the dwBuildNumber member of OSVERSIONINFOEX returned by GetVersionEx if you really want to detect Windows 11. From the Windows 11 release information page, a value 22000 and above for dwBuildNumber would indicate Windows 11.

Recommended Way: Quoting from this page: https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version

Identifying the current operating system is usually not the best way to determine whether a particular operating system feature is present. This is because the operating system may have had new features added in a redistributable DLL. Rather than using the Version API Helper functions to determine the operating system platform or version number, test for the presence of the feature itself.

To determine the best way to test for a feature, refer to the documentation for the feature of interest. The following list discusses some common techniques for feature detection:

You can test for the presence of the functions associated with a feature. To test for the presence of a function in a system DLL, call the LoadLibrary function to load the DLL. Then call the GetProcAddress function to determine whether the function of interest is present in the DLL. Use the pointer returned by GetProcAddress to call the function. Note that even if the function is present, it may be a stub that just returns an error code such as ERROR_CALL_NOT_IMPLEMENTED.
You can determine the presence of some features by using the GetSystemMetrics function. For example, you can detect multiple display monitors by calling GetSystemMetrics(SM_CMONITORS).
There are several versions of the redistributable DLLs that implement shell and common control features. For information about determining which versions are present on the system your application is running on, see the topic Shell and Common Controls Versions.
If you must require a particular operating system, be sure to use it as a minimum supported version, rather than design the test for the one operating system. This way, your detection code will continue to work on future versions of Windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文