Difference between revisions of "Check Version (Windows)"

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search
(Created page with '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…')
 
(from wpkg package)
Line 24: Line 24:
 
</check>
 
</check>
 
</source>
 
</source>
 +
 +
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.
  
 
===from batch file===
 
===from batch file===

Revision as of 21:39, 10 July 2010

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.

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" />

This apporach 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.

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 definded 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".