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 */
155 /* names to print out in debug traces */
156 static const char * const debug_names
[NB_WINDOWS_VERSIONS
] =
158 "Windows 2.0", /* WIN20 */
159 "Windows 3.0", /* WIN30 */
160 "Windows 3.1", /* WIN31 */
161 "Windows 95", /* WIN95 */
162 "Windows 98", /* WIN98 */
163 "Windows Me", /* WINME */
164 "Windows NT 3.51", /* NT351 */
165 "Windows NT 4.0", /* NT40 */
166 "Windows 2000", /* NT2K */
167 "Windows XP", /* WINXP */
168 "Windows Server 2003"/* WIN2K3 */
171 /* if one of the following dlls is importing ntdll the windows
172 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
173 static const WCHAR special_dlls
[][16] =
175 {'c','o','m','d','l','g','3','2','.','d','l','l',0},
176 {'c','o','m','c','t','l','3','2','.','d','l','l',0},
177 {'s','h','e','l','l','3','2','.','d','l','l',0},
178 {'o','l','e','3','2','.','d','l','l',0},
179 {'r','p','c','r','t','4','.','d','l','l',0}
182 /* the current version has not been autodetected but forced via cmdline */
183 static BOOL versionForced
= FALSE
;
184 static WINDOWS_VERSION forcedWinVersion
; /* init value irrelevant */
186 /**********************************************************************
189 * Parse the contents of the Version key.
191 static BOOL
parse_win_version( HANDLE hkey
)
193 static const WCHAR VersionW
[] = {'V','e','r','s','i','o','n',0};
195 UNICODE_STRING valueW
;
196 char tmp
[64], buffer
[50];
197 KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)tmp
;
201 RtlInitUnicodeString( &valueW
, VersionW
);
202 if (NtQueryValueKey( hkey
, &valueW
, KeyValuePartialInformation
, tmp
, sizeof(tmp
), &count
))
205 RtlUnicodeToMultiByteN( buffer
, sizeof(buffer
)-1, &len
, (WCHAR
*)info
->Data
, info
->DataLength
);
208 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
210 const char *p
, *pCurr
= WinVersionNames
[i
];
211 /* iterate through all winver aliases separated by comma */
213 p
= strchr(pCurr
, ',');
214 len
= p
? p
- pCurr
: strlen(pCurr
);
215 if ( (!strncmp( pCurr
, buffer
, len
)) && (buffer
[len
] == 0) )
217 forcedWinVersion
= i
;
218 versionForced
= TRUE
;
219 TRACE( "got win version %s\n", WinVersionNames
[forcedWinVersion
] );
226 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer
);
227 MESSAGE("Valid versions are:" );
228 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
230 /* only list the first, "official" alias in case of aliases */
231 const char *pCurr
= WinVersionNames
[i
];
232 const char *p
= strchr(pCurr
, ',');
233 len
= (p
) ? p
- pCurr
: strlen(pCurr
);
235 MESSAGE(" '%.*s'%c", (int)len
, pCurr
, (i
== NB_WINDOWS_VERSIONS
- 1) ? '\n' : ',' );
241 /**********************************************************************
244 void VERSION_Init( const WCHAR
*appname
)
246 OBJECT_ATTRIBUTES attr
;
247 UNICODE_STRING nameW
;
248 HANDLE root
, hkey
, config_key
;
249 static const WCHAR configW
[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
250 static const WCHAR appdefaultsW
[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
252 RtlOpenCurrentUser( KEY_ALL_ACCESS
, &root
);
253 attr
.Length
= sizeof(attr
);
254 attr
.RootDirectory
= root
;
255 attr
.ObjectName
= &nameW
;
257 attr
.SecurityDescriptor
= NULL
;
258 attr
.SecurityQualityOfService
= NULL
;
259 RtlInitUnicodeString( &nameW
, configW
);
261 /* @@ Wine registry key: HKCU\Software\Wine */
262 if (NtOpenKey( &config_key
, KEY_ALL_ACCESS
, &attr
)) config_key
= 0;
264 if (!config_key
) return;
266 /* open AppDefaults\\appname key */
267 if (appname
&& *appname
)
270 WCHAR appversion
[MAX_PATH
+20];
271 BOOL got_win_ver
= FALSE
;
273 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
274 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
276 strcpyW( appversion
, appdefaultsW
);
277 strcatW( appversion
, appname
);
278 TRACE( "getting version from %s\n", debugstr_w(appversion
) );
279 RtlInitUnicodeString( &nameW
, appversion
);
280 attr
.RootDirectory
= config_key
;
282 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
283 if (!NtOpenKey( &hkey
, KEY_ALL_ACCESS
, &attr
))
285 got_win_ver
= parse_win_version( hkey
);
288 if (got_win_ver
) goto done
;
291 TRACE( "getting default version\n" );
292 parse_win_version( config_key
);
295 NtClose( config_key
);
298 /**********************************************************************
302 * Don't call this function too early during the Wine init,
303 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
304 * be NULL in such cases, which causes the winver to ALWAYS be detected
306 * And as we cache the winver once it has been determined, this is bad.
307 * This can happen much easier than you might think, as this function
308 * is called by EVERY GetVersion*() API !
311 static const RTL_OSVERSIONINFOEXW
*VERSION_GetVersion(void)
313 static WORD winver
= WIN98
;
316 return &VersionData
[forcedWinVersion
]; /* user has overridden any sensible checks */
318 return &VersionData
[winver
];
322 /***********************************************************************
323 * RtlGetVersion (NTDLL.@)
325 NTSTATUS WINAPI
RtlGetVersion( RTL_OSVERSIONINFOEXW
*info
)
327 const RTL_OSVERSIONINFOEXW
* const current
= VERSION_GetVersion();
329 info
->dwMajorVersion
= current
->dwMajorVersion
;
330 info
->dwMinorVersion
= current
->dwMinorVersion
;
331 info
->dwBuildNumber
= current
->dwBuildNumber
;
332 info
->dwPlatformId
= current
->dwPlatformId
;
333 strcpyW( info
->szCSDVersion
, current
->szCSDVersion
);
334 if(info
->dwOSVersionInfoSize
== sizeof(RTL_OSVERSIONINFOEXW
))
336 info
->wServicePackMajor
= current
->wServicePackMajor
;
337 info
->wServicePackMinor
= current
->wServicePackMinor
;
338 info
->wSuiteMask
= current
->wSuiteMask
;
339 info
->wProductType
= current
->wProductType
;
341 TRACE("<-- %s (%s)\n", debug_names
[current
- VersionData
], debugstr_w(current
->szCSDVersion
) );
342 return STATUS_SUCCESS
;
346 /******************************************************************************
347 * RtlGetNtVersionNumbers (NTDLL.@)
349 * Get the version numbers of the run time library.
352 * major [O] Destination for the Major version
353 * minor [O] Destination for the Minor version
354 * build [O] Destination for the Build version
360 * Introduced in Windows XP (NT5.1)
362 void WINAPI
RtlGetNtVersionNumbers( LPDWORD major
, LPDWORD minor
, LPDWORD build
)
364 const RTL_OSVERSIONINFOEXW
* const current
= VERSION_GetVersion();
366 if (major
) *major
= current
->dwMajorVersion
;
367 if (minor
) *minor
= current
->dwMinorVersion
;
368 /* FIXME: Does anybody know the real formula? */
369 if (build
) *build
= (0xF0000000 | current
->dwBuildNumber
);
373 /******************************************************************************
374 * VerifyVersionInfoW (KERNEL32.@)
376 NTSTATUS WINAPI
RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW
*info
,
377 DWORD dwTypeMask
, DWORDLONG dwlConditionMask
)
379 RTL_OSVERSIONINFOEXW ver
;
382 FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n",
383 info
, dwTypeMask
, dwlConditionMask
);
386 - Check the following special case on Windows (various versions):
387 o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
388 o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
389 - MSDN talks about some tests being impossible. Check what really happens.
392 ver
.dwOSVersionInfoSize
= sizeof(ver
);
393 if ((status
= RtlGetVersion( &ver
)) != STATUS_SUCCESS
) return status
;
395 if(!(dwTypeMask
&& dwlConditionMask
)) return STATUS_INVALID_PARAMETER
;
397 if(dwTypeMask
& VER_PRODUCT_TYPE
)
398 switch(dwlConditionMask
>> 7*3 & 0x07) {
400 if(ver
.wProductType
!= info
->wProductType
) return STATUS_REVISION_MISMATCH
;
403 if(ver
.wProductType
<= info
->wProductType
) return STATUS_REVISION_MISMATCH
;
405 case VER_GREATER_EQUAL
:
406 if(ver
.wProductType
< info
->wProductType
) return STATUS_REVISION_MISMATCH
;
409 if(ver
.wProductType
>= info
->wProductType
) return STATUS_REVISION_MISMATCH
;
412 if(ver
.wProductType
> info
->wProductType
) return STATUS_REVISION_MISMATCH
;
415 return STATUS_INVALID_PARAMETER
;
417 if(dwTypeMask
& VER_SUITENAME
)
418 switch(dwlConditionMask
>> 6*3 & 0x07)
421 if((info
->wSuiteMask
& ver
.wSuiteMask
) != info
->wSuiteMask
)
422 return STATUS_REVISION_MISMATCH
;
425 if(!(info
->wSuiteMask
& ver
.wSuiteMask
) && info
->wSuiteMask
)
426 return STATUS_REVISION_MISMATCH
;
429 return STATUS_INVALID_PARAMETER
;
431 if(dwTypeMask
& VER_PLATFORMID
)
432 switch(dwlConditionMask
>> 3*3 & 0x07)
435 if(ver
.dwPlatformId
!= info
->dwPlatformId
) return STATUS_REVISION_MISMATCH
;
438 if(ver
.dwPlatformId
<= info
->dwPlatformId
) return STATUS_REVISION_MISMATCH
;
440 case VER_GREATER_EQUAL
:
441 if(ver
.dwPlatformId
< info
->dwPlatformId
) return STATUS_REVISION_MISMATCH
;
444 if(ver
.dwPlatformId
>= info
->dwPlatformId
) return STATUS_REVISION_MISMATCH
;
447 if(ver
.dwPlatformId
> info
->dwPlatformId
) return STATUS_REVISION_MISMATCH
;
450 return STATUS_INVALID_PARAMETER
;
452 if(dwTypeMask
& VER_BUILDNUMBER
)
453 switch(dwlConditionMask
>> 2*3 & 0x07)
456 if(ver
.dwBuildNumber
!= info
->dwBuildNumber
) return STATUS_REVISION_MISMATCH
;
459 if(ver
.dwBuildNumber
<= info
->dwBuildNumber
) return STATUS_REVISION_MISMATCH
;
461 case VER_GREATER_EQUAL
:
462 if(ver
.dwBuildNumber
< info
->dwBuildNumber
) return STATUS_REVISION_MISMATCH
;
465 if(ver
.dwBuildNumber
>= info
->dwBuildNumber
) return STATUS_REVISION_MISMATCH
;
468 if(ver
.dwBuildNumber
> info
->dwBuildNumber
) return STATUS_REVISION_MISMATCH
;
471 return STATUS_INVALID_PARAMETER
;
473 if(dwTypeMask
& VER_MAJORVERSION
)
474 switch(dwlConditionMask
>> 1*3 & 0x07)
477 if(ver
.dwMajorVersion
!= info
->dwMajorVersion
) return STATUS_REVISION_MISMATCH
;
480 if(ver
.dwMajorVersion
<= info
->dwMajorVersion
) return STATUS_REVISION_MISMATCH
;
482 case VER_GREATER_EQUAL
:
483 if(ver
.dwMajorVersion
< info
->dwMajorVersion
) return STATUS_REVISION_MISMATCH
;
486 if(ver
.dwMajorVersion
>= info
->dwMajorVersion
) return STATUS_REVISION_MISMATCH
;
489 if(ver
.dwMajorVersion
> info
->dwMajorVersion
) return STATUS_REVISION_MISMATCH
;
492 return STATUS_INVALID_PARAMETER
;
494 if(dwTypeMask
& VER_MINORVERSION
)
495 switch(dwlConditionMask
>> 0*3 & 0x07)
498 if(ver
.dwMinorVersion
!= info
->dwMinorVersion
) return STATUS_REVISION_MISMATCH
;
501 if(ver
.dwMinorVersion
<= info
->dwMinorVersion
) return STATUS_REVISION_MISMATCH
;
503 case VER_GREATER_EQUAL
:
504 if(ver
.dwMinorVersion
< info
->dwMinorVersion
) return STATUS_REVISION_MISMATCH
;
507 if(ver
.dwMinorVersion
>= info
->dwMinorVersion
) return STATUS_REVISION_MISMATCH
;
510 if(ver
.dwMinorVersion
> info
->dwMinorVersion
) return STATUS_REVISION_MISMATCH
;
513 return STATUS_INVALID_PARAMETER
;
515 if(dwTypeMask
& VER_SERVICEPACKMAJOR
)
516 switch(dwlConditionMask
>> 5*3 & 0x07)
519 if(ver
.wServicePackMajor
!= info
->wServicePackMajor
) return STATUS_REVISION_MISMATCH
;
522 if(ver
.wServicePackMajor
<= info
->wServicePackMajor
) return STATUS_REVISION_MISMATCH
;
524 case VER_GREATER_EQUAL
:
525 if(ver
.wServicePackMajor
< info
->wServicePackMajor
) return STATUS_REVISION_MISMATCH
;
528 if(ver
.wServicePackMajor
>= info
->wServicePackMajor
) return STATUS_REVISION_MISMATCH
;
531 if(ver
.wServicePackMajor
> info
->wServicePackMajor
) return STATUS_REVISION_MISMATCH
;
534 return STATUS_INVALID_PARAMETER
;
536 if(dwTypeMask
& VER_SERVICEPACKMINOR
)
537 switch(dwlConditionMask
>> 4*3 & 0x07)
540 if(ver
.wServicePackMinor
!= info
->wServicePackMinor
) return STATUS_REVISION_MISMATCH
;
543 if(ver
.wServicePackMinor
<= info
->wServicePackMinor
) return STATUS_REVISION_MISMATCH
;
545 case VER_GREATER_EQUAL
:
546 if(ver
.wServicePackMinor
< info
->wServicePackMinor
) return STATUS_REVISION_MISMATCH
;
549 if(ver
.wServicePackMinor
>= info
->wServicePackMinor
) return STATUS_REVISION_MISMATCH
;
552 if(ver
.wServicePackMinor
> info
->wServicePackMinor
) return STATUS_REVISION_MISMATCH
;
555 return STATUS_INVALID_PARAMETER
;
558 return STATUS_SUCCESS
;