Changes

Check Version (Windows)

3,711 bytes added, 23:12, 10 April 2010
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…'
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===
<source lang="xml">
<!-- 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" />
</source>
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:
<source lang="xml">
<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>
</source>

===from batch file===
<source lang="dos">
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
</source>
You now have a environment variable set to your version of Windows, which you can use to perform operations for a specific version, eg:
<source lang="dos">
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
)
</source>

===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===
<source lang="xml">
<check type="execute" path="%COMSPEC% /c if defined ProgramW6432 (exit /b 64) else (exit /b 32)" condition="exitcodeequalto" value="64" >
</source>
Above example will return true on a 64bit System and the package will not install.

===from batch file===
<source lang="dos">
if defined ProgramW6432 (
REM do 64bit specific stuff
) else (
REM do 32bit specific stuff
)
</source>

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

[[Category:Silent Installers]]
13
edits