Home > Backend Development > C++ > body text

How to Reliably Detect Windows 10 Version Across Platforms?

DDD
Release: 2024-11-05 18:32:02
Original
136 people have browsed it

How to Reliably Detect Windows 10 Version Across Platforms?

Cross-Platform Windows 10 Detection

Determining the Windows 10 version is often problematic due to the limitations of built-in functions like IsWindows10OrGreater(). This issue becomes even more pressing when cross-platform compatibility is desired.

A Universal Solution

To overcome these obstacles, it's suggested to employ the RtlGetVersion function. This function bypasses the compatibility shims and grants access to the true OS version. Although it's available in the DDK, it can also be invoked through runtime dynamic linking using the following code snippet:

typedef LONG NTSTATUS, *PNTSTATUS;
#define STATUS_SUCCESS (0x00000000)

typedef NTSTATUS (WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);

RTL_OSVERSIONINFOW GetRealOSVersion() {
    HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
    if (hMod) {
        RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion");
        if (fxPtr != nullptr) {
            RTL_OSVERSIONINFOW rovi = { 0 };
            rovi.dwOSVersionInfoSize = sizeof(rovi);
            if ( STATUS_SUCCESS == fxPtr(&rovi) ) {
                return rovi;
            }
        }
    }
    RTL_OSVERSIONINFOW rovi = { 0 };
    return rovi;
}
Copy after login

This snippet returns the actual OS version on Windows 10, even in the absence of a manifest.

An Alternative Approach

An alternative solution focuses on utilizing features rather than OS versions. This allows for a more flexible approach where different implementations are provided based on available capabilities.

The above is the detailed content of How to Reliably Detect Windows 10 Version Across Platforms?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!