1 /*
2 * versionhelpers.h
3 *
4 * Inline helper functions for Windows version detection
5 *
6 * This file is part of the ReactOS PSDK package.
7 *
8 * Contributors:
9 * Created by Timo Kreuzer <timo.kreuzer@reactos.org>
10 *
11 * THIS SOFTWARE IS NOT COPYRIGHTED
12 *
13 * This source code is offered for use in the public domain. You may
14 * use, modify or distribute it freely.
15 *
16 * This code is distributed in the hope that it will be useful but
17 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18 * DISCLAMED. This includes but is not limited to warranties of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 */
22
23 #pragma once
24 #define _versionhelpers_H_INCLUDED_
25
26 #include <specstrings.h>
27
28 #ifdef __cplusplus
29 #define VERSIONHELPERAPI inline bool
30 #else
31 #define VERSIONHELPERAPI FORCEINLINE BOOL
32 #endif
33
34 VERSIONHELPERAPI
IsWindowsVersionOrGreater(WORD wMajorVersion,WORD wMinorVersion,WORD wServicePackMajor)35 IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
36 {
37 OSVERSIONINFOEXW osvi = { sizeof(osvi), wMajorVersion, wMinorVersion, 0, 0, {0}, wServicePackMajor, 0, 0, 0, 0 };
38 DWORDLONG dwlConditionMask = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
39 dwlConditionMask = VerSetConditionMask(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
40 dwlConditionMask = VerSetConditionMask(dwlConditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
41
42 return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
43 }
44
45 VERSIONHELPERAPI
IsWindowsXPOrGreater()46 IsWindowsXPOrGreater()
47 {
48 return IsWindowsVersionOrGreater(5, 1, 0);
49 }
50
51 VERSIONHELPERAPI
IsWindowsXPSP1OrGreater()52 IsWindowsXPSP1OrGreater()
53 {
54 return IsWindowsVersionOrGreater(5, 1, 1);
55 }
56
57 VERSIONHELPERAPI
IsWindowsXPSP2OrGreater()58 IsWindowsXPSP2OrGreater()
59 {
60 return IsWindowsVersionOrGreater(5, 1, 2);
61 }
62
63 VERSIONHELPERAPI
IsWindowsXPSP3OrGreater()64 IsWindowsXPSP3OrGreater()
65 {
66 return IsWindowsVersionOrGreater(5, 1, 3);
67 }
68
69 VERSIONHELPERAPI
IsWindowsVistaOrGreater()70 IsWindowsVistaOrGreater()
71 {
72 return IsWindowsVersionOrGreater(6, 0, 0);
73 }
74
75 VERSIONHELPERAPI
IsWindowsVistaSP1OrGreater()76 IsWindowsVistaSP1OrGreater()
77 {
78 return IsWindowsVersionOrGreater(6, 0, 1);
79 }
80
81 VERSIONHELPERAPI
IsWindowsVistaSP2OrGreater()82 IsWindowsVistaSP2OrGreater()
83 {
84 return IsWindowsVersionOrGreater(6, 0, 2);
85 }
86
87 VERSIONHELPERAPI
IsWindows7OrGreater()88 IsWindows7OrGreater()
89 {
90 return IsWindowsVersionOrGreater(6, 1, 0);
91 }
92
93 VERSIONHELPERAPI
IsWindows7SP1OrGreater()94 IsWindows7SP1OrGreater()
95 {
96 return IsWindowsVersionOrGreater(6, 1, 1);
97 }
98
99 VERSIONHELPERAPI
IsWindows8OrGreater()100 IsWindows8OrGreater()
101 {
102 return IsWindowsVersionOrGreater(6, 2, 0);
103 }
104
105 VERSIONHELPERAPI
IsWindows8Point1OrGreater()106 IsWindows8Point1OrGreater()
107 {
108 return IsWindowsVersionOrGreater(6, 3, 0);
109 }
110
111 VERSIONHELPERAPI
IsWindowsThresholdOrGreater()112 IsWindowsThresholdOrGreater()
113 {
114 return IsWindowsVersionOrGreater(10, 0, 0);
115 }
116
117 VERSIONHELPERAPI
IsWindows10OrGreater()118 IsWindows10OrGreater()
119 {
120 return IsWindowsVersionOrGreater(10, 0, 0);
121 }
122
123 VERSIONHELPERAPI
IsWindowsServer()124 IsWindowsServer()
125 {
126 OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0, 0, VER_NT_WORKSTATION };
127 DWORDLONG const dwlConditionMask = VerSetConditionMask(0, VER_PRODUCT_TYPE, VER_EQUAL);
128 return VerifyVersionInfoW(&osvi, VER_PRODUCT_TYPE, dwlConditionMask) == FALSE;
129 }
130
131 VERSIONHELPERAPI
IsActiveSessionCountLimited()132 IsActiveSessionCountLimited()
133 {
134 OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0, 0, 0, 0 };
135 DWORDLONG dwlConditionMask = VerSetConditionMask(0, VER_SUITENAME, VER_AND);
136 BOOL fSuiteTerminal, fSuiteSingleUserTS;
137
138 osvi.wSuiteMask = VER_SUITE_TERMINAL;
139 fSuiteTerminal = VerifyVersionInfoW(&osvi, VER_SUITENAME, dwlConditionMask);
140
141 osvi.wSuiteMask = VER_SUITE_SINGLEUSERTS;
142 fSuiteSingleUserTS = VerifyVersionInfoW(&osvi, VER_SUITENAME, dwlConditionMask);
143
144 return !(fSuiteTerminal & !fSuiteSingleUserTS);
145 }
146
147 #ifdef __REACTOS__
148 VERSIONHELPERAPI
IsReactOS()149 IsReactOS()
150 {
151 // FIXME: Find a better method!
152 WCHAR szWinDir[MAX_PATH];
153 GetWindowsDirectoryW(szWinDir, _countof(szWinDir));
154 return (wcsstr(szWinDir, L"ReactOS") != NULL);
155 }
156 #endif // __REACTOS__
157