Check Version (Windows)

This is not a complete installer package, it's a collection of methods you can use to perform operations depending on the windows version you are using

Checking the version of Windows

The following examples show you how to determine which version of Windows you are running.

Note: since wpkg 1.2 you should better use Extended host attribute matching

from wpkg package

<!-- windows 2000 -->
<check type="registry" condition="equals" path="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" value="5.0" />
<!-- windows xp -->
<check type="registry" condition="equals" path="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" value="5.1" />
<!-- windows 2003 -->
<check type="registry" condition="equals" path="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" value="5.2" />
<!-- windows vista -->
<check type="registry" condition="equals" path="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" value="6.0" />
<!-- windows 7 -->
<check type="registry" condition="equals" path="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" value="6.1" />
<!-- windows 8 -->
<check type="registry" condition="equals" path="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" value="6.2" />
<!-- windows 8.1 -->
<check type="registry" condition="equals" path="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" value="6.3" />
<!-- windows 10 -->
<check type="registry" condition="equals" path="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" value="10.0" />

This approach can be used to limit a package to certain versions of windows; for example Windows7 already has Internet Explorer 8 installed, so to use a package in a mixed environment with xp and windows7 you could write a check like this:

<check type="logical" condition="or">
	<check type="uninstall" condition="exists" path="Windows Internet Explorer 8" />
	<check type="registry" condition="equals" path="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" value="6.1" />
</check>

The way this check works is that on Windows XP, wpkg would think that the package is already installed. This has a drawback: if you remove such a package, wpkg will try to remove this program every time on Windows XP systems, and then claim that the removal failed.

For more precise checks like Services Packs see also in HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion the ProductName and CSDVersion fields. There is an example in the Windows XP SP3 silent installer.

from batch file

VER | FINDSTR /IL "5.0" > NUL
IF %ERRORLEVEL% EQU 0 SET WinVersion=2000

VER | FINDSTR /IL "5.1." > NUL
IF %ERRORLEVEL% EQU 0 SET WinVersion=XP

VER | FINDSTR /IL "5.2." > NUL
IF %ERRORLEVEL% EQU 0 SET WinVersion=2003

VER | FINDSTR /IL "6.0." > NUL
IF %ERRORLEVEL% EQU 0 SET WinVersion=Vista

VER | FINDSTR /IL "6.1." > NUL
IF %ERRORLEVEL% EQU 0 SET WinVersion=7

You now have a environment variable set to your version of Windows, which you can use to perform operations for a specific version, eg:

IF %WinVersion% EQU "xp" (
REM do windows xp stuff
copy a file
execute some command
)
IF %WinVersion% EQU "Vista" (
REM do Vista stuff
xcopy a directory
execute some other command
)

limitations

Windows 7 and Windows 2008 R2 are based on the same kernel, so both will show up as version 6.1

To find the edition of Windows (Home, Professional, Ultimate) you have to look at the EditionID Key in the Registry under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\. From a Batch file you'll probably have to parse the output from the Systeminfo command.

Checking 32 or 64 bit

If you need to perform Install operations specific for 32bit or 64bit you can use the following checks

from wpkg package

<check type="execute" path="%COMSPEC% /c if defined ProgramW6432 (exit /b 64) else (exit /b 32)" condition="exitcodeequalto" value="64" >

Above example will return true on a 64bit System and the package will not install.

from batch file

if defined ProgramW6432 (
REM do 64bit specific stuff
) else (
REM do 32bit specific stuff
)

notes

The environment variable ProgramW6432 is only defined in 64bit versions of Windows.

Be careful when using the PROCESSOR_ARCHITECTURE environment Variable or reading the value from HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE, as multiple processors can run 64bit OS, including AMD64, IA64 and "things to come".