Updated version of an article that was originally published in the November 2000 issue of the InstallShield Newsletter
Abstract: With the release of Microsoft's latest operating system versions some developers are unsure how these can be detected and distinguished from each other. This is a problem especially if the setup authoring tool they are using is too old to have built in support for these new operating systems. This article describes how to determine whether a computer is running Windows 95 or 98, Windows Me, Windows NT 4 or Windows 2000. Instructions are given for InstallShield Professional versions 5.x and 6.x and Windows Installer.
The essential step to understand the identification of Windows types and versions is to recognize that there are only two "families" or technologies of 32 bit operating systems from Microsoft: 9x and NT. All Windows versions, including Windows 2000 and Windows Me, are members of any of these two families.
When you start a computer with Windows 2000, the splash screen already tells you that it is "based on NT technology". So without the influence of the marketing staff, Windows 2000 would probably have been called "Windows NT 5.0".
When Microsoft released Windows Me, some mockers called it "Windows 98 Third Edition" because many parts of it are identical to Windows 98. Of course there are some add-ons and even several substantial changes, but it is still a member of the Windows 9x family. This is also indicated by its version number, that has been set to 4.90.
|Operating System||Family||Version number|
|Windows 95||Windows 9x||4.00|
|Windows 98||Windows 9x||4.10|
|Windows Me||Windows 9x||4.90|
|Windows NT 4||Windows NT||4.00|
|Windows 2000||Windows NT||5.00|
Table 1: Windows version numbers
InstallShield's scripting language, that is not only supported in InstallShield Professional 5.x and 6.x, but also in InstallShield for Windows Installer (version 1.1 and above), includes the GetSystemInfo function that can be used to identify the operating system family and version. You do this in two steps, as shown in code sample 1. First you call GetSystemInfo with OS in the first parameter to find out the operating system family. Then you call it with WINMAJOR (and in case of Windows 9x one more time with WINMINOR) to get the Windows version number.
Calling the GetSystemInfo function to detect Windows Me works fine in InstallShield 6, but fails in InstallShield 5. This is because Windows Me returns 4.10 instead of 4.90 when asked for its version and therefore is identified as Windows 98.
To improve compatibility with older applications, Windows Me has a feature to "lie" about its version. Microsoft has created this function because some programs simply check the Windows version, and refuse to run if the version is higher than what the programmer expected when he created the application. Since most applications written for Windows 95 or 98 will also work on Windows Me, Windows circumvents the version test by returning 4.10 instead of 4.90 for such applications. Microsoft decided that setups created with InstallShield 5 belong to this group of programs, while it is okay to know the real Windows version for setups created with InstallShield 6.
The reasons for this operating system cloaking are questionable, but we have to live with it. This means that we must use other methods to distingush between Windows 98 and Me in InstallShield 5. Fortunately this isn't very hard: We can examine the file version of a core operating system file, e.g. Kernel32.dll. This can be done by calling the InstallShield functions VerGetFileVersion to retrieve the version, and VerCompare to see if the file version is 22.214.171.124 or above.
// InstallShield 6 requires that ifx.h be included #if _ISCRIPT_VER >= 0x600 #include "ifx.h" #endif NUMBER nvWinFamily, nvWinMajor, nvWinMinor; STRING svResult; program // Detect Windows family GetSystemInfo(OS, nvWinFamily, svResult); if ( nvWinFamily = IS_WINDOWSNT ) then // Check for NT 4 or Windows 2000 GetSystemInfo(WINMAJOR, nvWinMajor, svResult); if ( nvWinMajor >= 5 ) then MessageBox("Windows 2000 or above detected", INFORMATION); elseif ( nvWinMajor = 4 ) then MessageBox("Windows NT 4 detected", INFORMATION); elseif ( nvWinMajor = 3 ) then MessageBox("Windows NT 3 detected", INFORMATION); else MessageBox("Unknown Windows NT version", INFORMATION); endif; elseif ( nvWinFamily = IS_WINDOWS95 ) then // Check for Windows 95, Windows 98, or Windows Me GetSystemInfo(WINMAJOR, nvWinMajor, svResult); GetSystemInfo(WINMINOR, nvWinMinor, svResult); if ( nvWinMajor = 4 ) then if ( nvWinMinor >= 90 ) then MessageBox("Windows Me or above detected", INFORMATION); elseif ( nvWinMinor >= 10) then #if _ISCRIPT_VER >= 0x600 MessageBox("Windows 98 detected", INFORMATION); #else // In IS5 Windows Me lies about its version // so we check the file version of kernel32.dll VerGetFileVersion(WINSYSDIR ^ "kernel32.dll", svResult); if ( VerCompare(svResult, "126.96.36.199", VERSION) = LESS_THAN ) then MessageBox("Windows 98 detected", INFORMATION); else MessageBox("Windows Me or above detected", INFORMATION); endif; #endif else MessageBox("Windows 95 detected", INFORMATION); endif; else MessageBox("Unknown Windows 9x version", INFORMATION); endif; else MessageBox("No 32 bit operating system", WARNING); endif; endprogram
Code sample 1: Calling GetSystemInfo
Remarks about code sample 1:
In InstallShield Professional 6.x (and InstallShield for Windows Installer 1.1 and above, which uses the same scripting engine) you don't need to call the GetSystemInfo function - InstallShield does this for you behind the scenes during initialisation, and stores the results in the SYSINFO structure. Since this structure already has a member to identify Windows 2000, less code is required (see figure 2)
#include "ifx.h" NUMBER nvWinFamily, nvWinMajor, nvWinMinor; STRING svResult; program if ( SYSINFO.WINNT.bWin2000 ) then MessageBox("Windows 2000 detected", INFORMATION); elseif ( SYSINFO.WINNT.bWinNT4 ) then MessageBox("Windows NT 4 detected", INFORMATION); elseif ( SYSINFO.WINNT.bWinNT351 ) then MessageBox("Windows NT 3 detected", INFORMATION); elseif ( SYSINFO.WINNT.bWinNT ) then MessageBox("Unknown Windows NT version", INFORMATION); elseif ( SYSINFO.WIN9X.bWin98 ) then MessageBox("Windows 98 detected", INFORMATION); elseif ( SYSINFO.WIN9X.bWin95 ) then MessageBox("Windows 95 detected", INFORMATION); elseif ( SYSINFO.WIN9X.bWin9X ) then MessageBox("Windows Me or above detected", INFORMATION); else MessageBox("No 32 bit operating system", WARNING); endif; endprogram
Code sample 2: Using the SYSINFO structure
Remarks about code sample 2:
In InstallShield Professional - Windows Installer Edition you don't have to write custom code to identify the operating system. The Windows Installer engine provides two built in properties for this purpose: Version9X and VersionNT. The following table shows their values:
|Windows NT 4||400|
Table 2: Operating system properties in Windows Installer
Here are some examples of conditions based on operating system:
|VersionNT>=500||Evaluates to TRUE only on Windows 2000 and above, but FALSE on Windows 95, 98, Me and NT 4|
|Version9X||Evaluates to TRUE on Windows 95, 98, Me and above, but FALSE on Windows NT 4, 2000 and above|
|(Version9X=490) Or (VersionNT=500)||Evaluates to TRUE only on Windows Me and Windows 2000.|
Stefan Krueger is working as freelance setup consultant. Besides his contract work, he answers questions in various newsgroups and maintains the InstallSite.org web site, a place where setup developers share resources and information among peers.
If you have any comments about this article, or want to suggest a topic that Stefan should discuss in a future article, please write to . To read Stefan's articles from previous issues of the InstallShield Newsletter, please visit http://www.installsite.org/isnews.htm.
|News||Discussions||Windows Installer||Related Tools||More Help||InstallScript||About InstallSite||Shop||Site Search|
|Neuigkeiten||Diskussionsgruppen||Windows Installer||MSI FAQ||Artikel||Shop||Suche|
Copyright © by InstallSite Stefan
Krueger. All rights reserved. Legal
By using this site you agree to the license agreement. Webmaster contact