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"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
37 #include "ntdll_misc.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ver);
43 WIN20, /* Windows 2.0 */
44 WIN30, /* Windows 3.0 */
45 WIN31, /* Windows 3.1 */
46 WIN95, /* Windows 95 */
47 WIN98, /* Windows 98 */
48 WINME, /* Windows Me */
49 NT351, /* Windows NT 3.51 */
50 NT40, /* Windows NT 4.0 */
51 NT2K, /* Windows 2000 */
52 WINXP, /* Windows XP */
53 WIN2K3, /* Windows 2003 */
57 /* FIXME: compare values below with original and fix.
58 * An *excellent* win9x version page (ALL versions !)
59 * can be found at members.aol.com/axcel216/ver.htm */
60 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
62 /* WIN20 FIXME: verify values */
64 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
65 {'W','i','n','3','2','s',' ','1','.','3',0},
68 /* WIN30 FIXME: verify values */
70 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
71 {'W','i','n','3','2','s',' ','1','.','3',0},
76 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
77 {'W','i','n','3','2','s',' ','1','.','3',0},
82 /* Win95: 4, 0, 0x40003B6, ""
83 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
84 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
85 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
86 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
87 * Win95a/b can be discerned via regkey SubVersionNumber
89 * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
91 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
95 /* WIN98 (second edition) */
97 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
98 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
100 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
106 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
112 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
113 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
118 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
119 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
120 6, 0, 0, VER_NT_WORKSTATION, 0
124 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
125 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
126 4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
130 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
131 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
132 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
136 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
137 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
138 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
142 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
143 { /* no spaces in here ! */
152 "win2000,win2k,nt2k,nt2000", /* NT2K */
154 "win2003,win2k3" /* WIN2K3 */
157 /* names to print out in debug traces */
158 static const char * const debug_names[NB_WINDOWS_VERSIONS] =
160 "Windows 2.0", /* WIN20 */
161 "Windows 3.0", /* WIN30 */
162 "Windows 3.1", /* WIN31 */
163 "Windows 95", /* WIN95 */
164 "Windows 98", /* WIN98 */
165 "Windows Me", /* WINME */
166 "Windows NT 3.51", /* NT351 */
167 "Windows NT 4.0", /* NT40 */
168 "Windows 2000", /* NT2K */
169 "Windows XP", /* WINXP */
170 "Windows Server 2003"/* WIN2K3 */
173 /* if one of the following dlls is importing ntdll the windows
174 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
175 static const WCHAR special_dlls[][16] =
177 {'c','o','m','d','l','g','3','2','.','d','l','l',0},
178 {'c','o','m','c','t','l','3','2','.','d','l','l',0},
179 {'s','h','e','l','l','3','2','.','d','l','l',0},
180 {'o','l','e','3','2','.','d','l','l',0},
181 {'r','p','c','r','t','4','.','d','l','l',0}
184 /* the current version has not been autodetected but forced via cmdline */
185 static BOOL versionForced = FALSE;
186 static WINDOWS_VERSION forcedWinVersion; /* init value irrelevant */
188 /**********************************************************************
191 * Parse the contents of the Version key.
193 static BOOL parse_win_version( HKEY hkey )
195 static const WCHAR WindowsW[] = {'W','i','n','d','o','w','s',0};
197 UNICODE_STRING valueW;
198 char tmp[64], buffer[50];
199 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
203 RtlInitUnicodeString( &valueW, WindowsW );
204 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
207 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
210 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
212 const char *p, *pCurr = WinVersionNames[i];
213 /* iterate through all winver aliases separated by comma */
215 p = strchr(pCurr, ',');
216 len = p ? p - pCurr : strlen(pCurr);
217 if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
219 forcedWinVersion = i;
220 versionForced = TRUE;
221 TRACE( "got win version %s\n", WinVersionNames[forcedWinVersion] );
228 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
229 MESSAGE("Valid versions are:" );
230 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
232 /* only list the first, "official" alias in case of aliases */
233 const char *pCurr = WinVersionNames[i];
234 const char *p = strchr(pCurr, ',');
235 len = (p) ? p - pCurr : strlen(pCurr);
237 MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
243 /**********************************************************************
246 void VERSION_Init( const WCHAR *appname )
248 OBJECT_ATTRIBUTES attr;
249 UNICODE_STRING nameW;
250 HKEY hkey, config_key;
251 static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
252 'S','o','f','t','w','a','r','e','\\',
253 'W','i','n','e','\\',
254 'W','i','n','e','\\',
255 'C','o','n','f','i','g',0};
256 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
257 static const WCHAR versionW[] = {'\\','V','e','r','s','i','o','n',0};
259 attr.Length = sizeof(attr);
260 attr.RootDirectory = 0;
261 attr.ObjectName = &nameW;
263 attr.SecurityDescriptor = NULL;
264 attr.SecurityQualityOfService = NULL;
265 RtlInitUnicodeString( &nameW, configW );
267 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) return;
268 attr.RootDirectory = config_key;
270 /* open AppDefaults\\appname\\Version key */
271 if (appname && *appname)
274 WCHAR appversion[MAX_PATH+20];
275 BOOL got_win_ver = FALSE;
277 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
278 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
280 strcpyW( appversion, appdefaultsW );
281 strcatW( appversion, appname );
282 strcatW( appversion, versionW );
283 TRACE( "getting version from %s\n", debugstr_w(appversion) );
284 RtlInitUnicodeString( &nameW, appversion );
286 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
288 got_win_ver = parse_win_version( hkey );
291 if (got_win_ver) goto done;
294 TRACE( "getting default version\n" );
295 RtlInitUnicodeString( &nameW, versionW + 1 );
296 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
298 parse_win_version( hkey );
303 NtClose( config_key );
306 /**********************************************************************
310 * Don't call this function too early during the Wine init,
311 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
312 * be NULL in such cases, which causes the winver to ALWAYS be detected
314 * And as we cache the winver once it has been determined, this is bad.
315 * This can happen much easier than you might think, as this function
316 * is called by EVERY GetVersion*() API !
319 static const RTL_OSVERSIONINFOEXW *VERSION_GetVersion(void)
321 static WORD winver = WIN98;
324 return &VersionData[forcedWinVersion]; /* user has overridden any sensible checks */
326 return &VersionData[winver];
330 /***********************************************************************
331 * RtlGetVersion (NTDLL.@)
333 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
335 const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
337 info->dwMajorVersion = current->dwMajorVersion;
338 info->dwMinorVersion = current->dwMinorVersion;
339 info->dwBuildNumber = current->dwBuildNumber;
340 info->dwPlatformId = current->dwPlatformId;
341 strcpyW( info->szCSDVersion, current->szCSDVersion );
342 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
344 info->wServicePackMajor = current->wServicePackMajor;
345 info->wServicePackMinor = current->wServicePackMinor;
346 info->wSuiteMask = current->wSuiteMask;
347 info->wProductType = current->wProductType;
349 TRACE("<-- %s (%s)\n", debug_names[current - VersionData], debugstr_w(current->szCSDVersion) );
350 return STATUS_SUCCESS;
354 /******************************************************************************
355 * RtlGetNtVersionNumbers (NTDLL.@)
357 * Get the version numbers of the run time library.
360 * major [O] Destination for the Major version
361 * minor [O] Destination for the Minor version
362 * build [O] Destination for the Build version
368 * Introduced in Windows XP (NT5.1)
370 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
372 const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
374 if (major) *major = current->dwMajorVersion;
375 if (minor) *minor = current->dwMinorVersion;
376 /* FIXME: Does anybody know the real formula? */
377 if (build) *build = (0xF0000000 | current->dwBuildNumber);
381 /******************************************************************************
382 * VerifyVersionInfoW (KERNEL32.@)
384 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
385 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
387 RTL_OSVERSIONINFOEXW ver;
390 FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n",
391 info, dwTypeMask, dwlConditionMask);
394 - Check the following special case on Windows (various versions):
395 o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
396 o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
397 - MSDN talks about some tests being impossible. Check what really happens.
400 ver.dwOSVersionInfoSize = sizeof(ver);
401 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
403 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
405 if(dwTypeMask & VER_PRODUCT_TYPE)
406 switch(dwlConditionMask >> 7*3 & 0x07) {
408 if(ver.wProductType != info->wProductType) return STATUS_REVISION_MISMATCH;
411 if(ver.wProductType <= info->wProductType) return STATUS_REVISION_MISMATCH;
413 case VER_GREATER_EQUAL:
414 if(ver.wProductType < info->wProductType) return STATUS_REVISION_MISMATCH;
417 if(ver.wProductType >= info->wProductType) return STATUS_REVISION_MISMATCH;
420 if(ver.wProductType > info->wProductType) return STATUS_REVISION_MISMATCH;
423 return STATUS_INVALID_PARAMETER;
425 if(dwTypeMask & VER_SUITENAME)
426 switch(dwlConditionMask >> 6*3 & 0x07)
429 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
430 return STATUS_REVISION_MISMATCH;
433 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
434 return STATUS_REVISION_MISMATCH;
437 return STATUS_INVALID_PARAMETER;
439 if(dwTypeMask & VER_PLATFORMID)
440 switch(dwlConditionMask >> 3*3 & 0x07)
443 if(ver.dwPlatformId != info->dwPlatformId) return STATUS_REVISION_MISMATCH;
446 if(ver.dwPlatformId <= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
448 case VER_GREATER_EQUAL:
449 if(ver.dwPlatformId < info->dwPlatformId) return STATUS_REVISION_MISMATCH;
452 if(ver.dwPlatformId >= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
455 if(ver.dwPlatformId > info->dwPlatformId) return STATUS_REVISION_MISMATCH;
458 return STATUS_INVALID_PARAMETER;
460 if(dwTypeMask & VER_BUILDNUMBER)
461 switch(dwlConditionMask >> 2*3 & 0x07)
464 if(ver.dwBuildNumber != info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
467 if(ver.dwBuildNumber <= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
469 case VER_GREATER_EQUAL:
470 if(ver.dwBuildNumber < info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
473 if(ver.dwBuildNumber >= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
476 if(ver.dwBuildNumber > info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
479 return STATUS_INVALID_PARAMETER;
481 if(dwTypeMask & VER_MAJORVERSION)
482 switch(dwlConditionMask >> 1*3 & 0x07)
485 if(ver.dwMajorVersion != info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
488 if(ver.dwMajorVersion <= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
490 case VER_GREATER_EQUAL:
491 if(ver.dwMajorVersion < info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
494 if(ver.dwMajorVersion >= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
497 if(ver.dwMajorVersion > info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
500 return STATUS_INVALID_PARAMETER;
502 if(dwTypeMask & VER_MINORVERSION)
503 switch(dwlConditionMask >> 0*3 & 0x07)
506 if(ver.dwMinorVersion != info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
509 if(ver.dwMinorVersion <= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
511 case VER_GREATER_EQUAL:
512 if(ver.dwMinorVersion < info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
515 if(ver.dwMinorVersion >= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
518 if(ver.dwMinorVersion > info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
521 return STATUS_INVALID_PARAMETER;
523 if(dwTypeMask & VER_SERVICEPACKMAJOR)
524 switch(dwlConditionMask >> 5*3 & 0x07)
527 if(ver.wServicePackMajor != info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
530 if(ver.wServicePackMajor <= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
532 case VER_GREATER_EQUAL:
533 if(ver.wServicePackMajor < info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
536 if(ver.wServicePackMajor >= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
539 if(ver.wServicePackMajor > info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
542 return STATUS_INVALID_PARAMETER;
544 if(dwTypeMask & VER_SERVICEPACKMINOR)
545 switch(dwlConditionMask >> 4*3 & 0x07)
548 if(ver.wServicePackMinor != info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
551 if(ver.wServicePackMinor <= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
553 case VER_GREATER_EQUAL:
554 if(ver.wServicePackMinor < info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
557 if(ver.wServicePackMinor >= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
560 if(ver.wServicePackMinor > info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
563 return STATUS_INVALID_PARAMETER;
566 return STATUS_SUCCESS;