Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qoperatingsystemversion_win.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
8
9#include <qt_windows.h>
10#include <qbytearray.h>
11
13
15{
16 OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0};
17
18 HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
19 if (Q_UNLIKELY(!ntdll))
20 return result;
21
22 typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO);
23
24 // RtlGetVersion is documented public API but we must load it dynamically
25 // because linking to it at load time will not pass the Windows App Certification Kit
26 // https://msdn.microsoft.com/en-us/library/windows/hardware/ff561910.aspx
27 RtlGetVersionFunction pRtlGetVersion = reinterpret_cast<RtlGetVersionFunction>(
28 reinterpret_cast<QFunctionPointer>(GetProcAddress(ntdll, "RtlGetVersion")));
29 if (Q_UNLIKELY(!pRtlGetVersion))
30 return result;
31
32 // GetVersionEx() has been deprecated in Windows 8.1 and will return
33 // only Windows 8 from that version on, so use the kernel API function.
34 pRtlGetVersion(reinterpret_cast<LPOSVERSIONINFO>(&result)); // always returns STATUS_SUCCESS
35 return result;
36}
37
39{
40 OSVERSIONINFOEX realResult = determineWinOsVersion();
41#ifdef QT_DEBUG
42 {
43 if (Q_UNLIKELY(qEnvironmentVariableIsSet("QT_WINVER_OVERRIDE"))) {
44 OSVERSIONINFOEX result = realResult;
45 result.dwMajorVersion = 0;
46 result.dwMinorVersion = 0;
47
48 // Erase any build number and service pack information
49 result.dwBuildNumber = 0;
50 result.szCSDVersion[0] = L'\0';
51 result.wServicePackMajor = 0;
52 result.wServicePackMinor = 0;
53
54 const QByteArray winVerOverride = qgetenv("QT_WINVER_OVERRIDE");
55 if (winVerOverride == "WINDOWS10" || winVerOverride == "2016"
56 || winVerOverride == "2019" || winVerOverride == "2022") {
57 result.dwMajorVersion = 10;
58 } else if (winVerOverride == "WINDOWS11") {
59 result.dwMajorVersion = 10;
60 result.dwBuildNumber = 22000;
61 } else {
62 return realResult;
63 }
64
65 if (winVerOverride == "2016" || winVerOverride == "2019"
66 || winVerOverride == "2022") {
67 // If the current host OS is a domain controller and the override OS
68 // is also a server type OS, preserve that information
69 if (result.wProductType == VER_NT_WORKSTATION)
70 result.wProductType = VER_NT_SERVER;
71 } else {
72 // Any other OS must be a workstation OS type
73 result.wProductType = VER_NT_WORKSTATION;
74 }
75 }
76 }
77#endif
78 return realResult;
79}
80
82{
84 v.m_os = currentType();
85 const OSVERSIONINFOEX osv = qWindowsVersionInfo();
86 v.m_major = osv.dwMajorVersion;
87 v.m_minor = osv.dwMinorVersion;
88 v.m_micro = osv.dwBuildNumber;
89 return v;
90}
91
92QT_END_NAMESPACE
static constexpr OSType currentType()
Combined button and popup list for selecting options.
OSVERSIONINFOEX qWindowsVersionInfo()
static QT_BEGIN_NAMESPACE OSVERSIONINFOEX determineWinOsVersion()