Jump to content

Checking for existing/prior versions


lamaslany

Recommended Posts

Can anyone suggest some good reading material (or even provide examples!) of how to check whether an application is already installed and/or a previous version...

For example: Adobe Acrobat Reader. Is it possible to test whether the software is already installed and whether an earlier version is already installed?

Many thanks in advance for any assistance you can offer,

lamaslany

Link to comment
Share on other sites


Option Explicit
Dim ws, fs, strComputer, objWMIService, colSoftware, objSoftware
Set ws = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product")
For Each objSoftware in colSoftware
If Left(objSoftware.Name, 12) = "Adobe Reader" Then
WScript.Echo objSoftware.Name & " is installed."
WScript.Echo "The installed version is: " & objSoftware.Version
End If
Next

Link to comment
Share on other sites

I'll stick with enumerating the registry.

This is what I would use based on AutoIt3

$result = _InstalledVersion('Adobe Reader')
If Not @error Then MsgBox(0, 'Installed Version', $result)

Func _InstalledVersion($displayname)
Local $key_main = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
Local $i, $key_main, $key_result, $key_sub, $version
For $i = 1 To 1000
$key_sub = RegEnumKey($key_main, $i)
If @error Then ExitLoop
If RegRead($key_main & '\' & $key_sub, 'DisplayName') = $displayname Then
$version = RegRead($key_main & '\' & $key_sub, 'DisplayVersion')
If Not $version Or @error Then ContinueLoop
Return $version
EndIf
Next
SetError(1)
Return
EndFunc

Edit:

Rude of me to forget, thanks for your reply, RogueSpear

Edited by MHz
Link to comment
Share on other sites

@MHz, something to watch out for there is that the entry is not always exactly "Adobe Reader". I've seen it with a version number afterwards. That's why I keyed on the beginning of the string.

The UDF I show relies on what you view in Add/Remove programs. If a program maker changes the name like changing pants, then real problems in identifing does come in. Yes, indeed entries can change as they sometimes add version number, so I will add in a StringLeft to handle the name without the rest. Thanks RogueSpear ;)

Add code here for comparison.

$result = _InstalledVersion('Adobe Reader')
If Not @error Then MsgBox(0, 'Installed Version', $result)

Func _InstalledVersion($displayname)
Local $key_main = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
Local $i, $key_main, $key_result, $key_sub, $version, $size = StringLen($displayname)
For $i = 1 To 1000
$key_sub = RegEnumKey($key_main, $i)
If @error Then ExitLoop
If StringLeft(RegRead($key_main & '\' & $key_sub, 'DisplayName'), $size) = $displayname Then
$version = RegRead($key_main & '\' & $key_sub, 'DisplayVersion')
If Not $version Or @error Then ContinueLoop
Return $version
EndIf
Next
SetError(1)
Return
EndFunc

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...