2 * Windows and DOS version functions
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Patrik Stridvall
6 * Copyright 1998, 2003 Andreas Mohr
7 * Copyright 1997, 2003 Alexandre Julliard
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/port.h"
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
35 #include "ntdll_misc.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ver);
41 WIN20, /* Windows 2.0 */
42 WIN30, /* Windows 3.0 */
43 WIN31, /* Windows 3.1 */
44 WIN95, /* Windows 95 */
45 WIN98, /* Windows 98 */
46 WINME, /* Windows Me */
47 NT351, /* Windows NT 3.51 */
48 NT40, /* Windows NT 4.0 */
49 NT2K, /* Windows 2000 */
50 WINXP, /* Windows XP */
51 WIN2K3, /* Windows 2003 */
55 /* FIXME: compare values below with original and fix.
56 * An *excellent* win9x version page (ALL versions !)
57 * can be found at members.aol.com/axcel216/ver.htm */
58 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
60 /* WIN20 FIXME: verify values */
62 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
63 {'W','i','n','3','2','s',' ','1','.','3',0},
66 /* WIN30 FIXME: verify values */
68 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
69 {'W','i','n','3','2','s',' ','1','.','3',0},
74 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
75 {'W','i','n','3','2','s',' ','1','.','3',0},
80 /* Win95: 4, 0, 0x40003B6, ""
81 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
82 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
83 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
84 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
85 * Win95a/b can be discerned via regkey SubVersionNumber
87 * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
89 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
93 /* WIN98 (second edition) */
95 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
96 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
98 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
104 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
110 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
111 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
116 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
117 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
118 6, 0, 0, VER_NT_WORKSTATION, 0
122 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
123 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
124 4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
128 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
129 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
130 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
134 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
135 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
136 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
140 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
141 { /* no spaces in here ! */
150 "win2000,win2k,nt2k,nt2000", /* NT2K */
152 "win2003,win2k3" /* WIN2K3 */
156 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
157 static const RTL_OSVERSIONINFOEXW *current_version;
159 /**********************************************************************
162 * Parse the contents of the Version key.
164 static BOOL parse_win_version( HANDLE hkey )
166 static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
168 UNICODE_STRING valueW;
169 char tmp[64], buffer[50];
170 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
174 RtlInitUnicodeString( &valueW, VersionW );
175 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
178 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
181 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
183 const char *p, *pCurr = WinVersionNames[i];
184 /* iterate through all winver aliases separated by comma */
186 p = strchr(pCurr, ',');
187 len = p ? p - pCurr : strlen(pCurr);
188 if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
190 current_version = &VersionData[i];
191 TRACE( "got win version %s\n", WinVersionNames[i] );
198 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
199 MESSAGE("Valid versions are:" );
200 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
202 /* only list the first, "official" alias in case of aliases */
203 const char *pCurr = WinVersionNames[i];
204 const char *p = strchr(pCurr, ',');
205 len = (p) ? p - pCurr : strlen(pCurr);
207 MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
213 /**********************************************************************
216 void version_init( const WCHAR *appname )
218 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
219 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
221 OBJECT_ATTRIBUTES attr;
222 UNICODE_STRING nameW;
223 HANDLE root, hkey, config_key;
224 BOOL got_win_ver = FALSE;
226 current_version = &VersionData[WIN98]; /* default if nothing else is specified */
228 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
229 attr.Length = sizeof(attr);
230 attr.RootDirectory = root;
231 attr.ObjectName = &nameW;
233 attr.SecurityDescriptor = NULL;
234 attr.SecurityQualityOfService = NULL;
235 RtlInitUnicodeString( &nameW, configW );
237 /* @@ Wine registry key: HKCU\Software\Wine */
238 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
240 if (!config_key) goto done;
242 /* open AppDefaults\\appname key */
243 if (appname && *appname)
246 WCHAR appversion[MAX_PATH+20];
248 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
249 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
251 strcpyW( appversion, appdefaultsW );
252 strcatW( appversion, appname );
253 RtlInitUnicodeString( &nameW, appversion );
254 attr.RootDirectory = config_key;
256 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
257 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
259 TRACE( "getting version from %s\n", debugstr_w(appversion) );
260 got_win_ver = parse_win_version( hkey );
267 TRACE( "getting default version\n" );
268 parse_win_version( config_key );
270 NtClose( config_key );
273 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
274 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
275 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
276 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
278 TRACE( "got %ld.%ld plaform %ld build %lx name %s\n",
279 current_version->dwMajorVersion, current_version->dwMinorVersion,
280 current_version->dwPlatformId, current_version->dwBuildNumber,
281 debugstr_w( current_version->szCSDVersion ));
285 /***********************************************************************
286 * RtlGetVersion (NTDLL.@)
288 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
290 info->dwMajorVersion = current_version->dwMajorVersion;
291 info->dwMinorVersion = current_version->dwMinorVersion;
292 info->dwBuildNumber = current_version->dwBuildNumber;
293 info->dwPlatformId = current_version->dwPlatformId;
294 strcpyW( info->szCSDVersion, current_version->szCSDVersion );
295 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
297 info->wServicePackMajor = current_version->wServicePackMajor;
298 info->wServicePackMinor = current_version->wServicePackMinor;
299 info->wSuiteMask = current_version->wSuiteMask;
300 info->wProductType = current_version->wProductType;
302 return STATUS_SUCCESS;
306 /******************************************************************************
307 * RtlGetNtVersionNumbers (NTDLL.@)
309 * Get the version numbers of the run time library.
312 * major [O] Destination for the Major version
313 * minor [O] Destination for the Minor version
314 * build [O] Destination for the Build version
320 * Introduced in Windows XP (NT5.1)
322 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
324 if (major) *major = current_version->dwMajorVersion;
325 if (minor) *minor = current_version->dwMinorVersion;
326 /* FIXME: Does anybody know the real formula? */
327 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
331 /******************************************************************************
332 * RtlGetNtProductType (NTDLL.@)
334 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
336 if (type) *type = current_version->wProductType;
341 /******************************************************************************
342 * VerifyVersionInfoW (KERNEL32.@)
344 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
345 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
347 RTL_OSVERSIONINFOEXW ver;
350 FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n",
351 info, dwTypeMask, dwlConditionMask);
354 - Check the following special case on Windows (various versions):
355 o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
356 o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
357 - MSDN talks about some tests being impossible. Check what really happens.
360 ver.dwOSVersionInfoSize = sizeof(ver);
361 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
363 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
365 if(dwTypeMask & VER_PRODUCT_TYPE)
366 switch(dwlConditionMask >> 7*3 & 0x07) {
368 if(ver.wProductType != info->wProductType) return STATUS_REVISION_MISMATCH;
371 if(ver.wProductType <= info->wProductType) return STATUS_REVISION_MISMATCH;
373 case VER_GREATER_EQUAL:
374 if(ver.wProductType < info->wProductType) return STATUS_REVISION_MISMATCH;
377 if(ver.wProductType >= info->wProductType) return STATUS_REVISION_MISMATCH;
380 if(ver.wProductType > info->wProductType) return STATUS_REVISION_MISMATCH;
383 return STATUS_INVALID_PARAMETER;
385 if(dwTypeMask & VER_SUITENAME)
386 switch(dwlConditionMask >> 6*3 & 0x07)
389 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
390 return STATUS_REVISION_MISMATCH;
393 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
394 return STATUS_REVISION_MISMATCH;
397 return STATUS_INVALID_PARAMETER;
399 if(dwTypeMask & VER_PLATFORMID)
400 switch(dwlConditionMask >> 3*3 & 0x07)
403 if(ver.dwPlatformId != info->dwPlatformId) return STATUS_REVISION_MISMATCH;
406 if(ver.dwPlatformId <= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
408 case VER_GREATER_EQUAL:
409 if(ver.dwPlatformId < info->dwPlatformId) return STATUS_REVISION_MISMATCH;
412 if(ver.dwPlatformId >= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
415 if(ver.dwPlatformId > info->dwPlatformId) return STATUS_REVISION_MISMATCH;
418 return STATUS_INVALID_PARAMETER;
420 if(dwTypeMask & VER_BUILDNUMBER)
421 switch(dwlConditionMask >> 2*3 & 0x07)
424 if(ver.dwBuildNumber != info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
427 if(ver.dwBuildNumber <= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
429 case VER_GREATER_EQUAL:
430 if(ver.dwBuildNumber < info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
433 if(ver.dwBuildNumber >= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
436 if(ver.dwBuildNumber > info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
439 return STATUS_INVALID_PARAMETER;
441 if(dwTypeMask & VER_MAJORVERSION)
442 switch(dwlConditionMask >> 1*3 & 0x07)
445 if(ver.dwMajorVersion != info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
448 if(ver.dwMajorVersion <= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
450 case VER_GREATER_EQUAL:
451 if(ver.dwMajorVersion < info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
454 if(ver.dwMajorVersion >= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
457 if(ver.dwMajorVersion > info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
460 return STATUS_INVALID_PARAMETER;
462 if(dwTypeMask & VER_MINORVERSION)
463 switch(dwlConditionMask >> 0*3 & 0x07)
466 if(ver.dwMinorVersion != info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
469 if(ver.dwMinorVersion <= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
471 case VER_GREATER_EQUAL:
472 if(ver.dwMinorVersion < info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
475 if(ver.dwMinorVersion >= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
478 if(ver.dwMinorVersion > info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
481 return STATUS_INVALID_PARAMETER;
483 if(dwTypeMask & VER_SERVICEPACKMAJOR)
484 switch(dwlConditionMask >> 5*3 & 0x07)
487 if(ver.wServicePackMajor != info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
490 if(ver.wServicePackMajor <= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
492 case VER_GREATER_EQUAL:
493 if(ver.wServicePackMajor < info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
496 if(ver.wServicePackMajor >= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
499 if(ver.wServicePackMajor > info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
502 return STATUS_INVALID_PARAMETER;
504 if(dwTypeMask & VER_SERVICEPACKMINOR)
505 switch(dwlConditionMask >> 4*3 & 0x07)
508 if(ver.wServicePackMinor != info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
511 if(ver.wServicePackMinor <= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
513 case VER_GREATER_EQUAL:
514 if(ver.wServicePackMinor < info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
517 if(ver.wServicePackMinor >= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
520 if(ver.wServicePackMinor > info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
523 return STATUS_INVALID_PARAMETER;
526 return STATUS_SUCCESS;