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
Page 1 of 1
Checking for existing/prior versions and handling occurances through scripting...
#2
Posted 10 April 2006 - 09:34 AM
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
#3
Posted 11 April 2006 - 07:07 AM
Hey RogueSpear,
That VBS using WMI would not work at T-12 (Cmdlines.txt) , correct?
That VBS using WMI would not work at T-12 (Cmdlines.txt) , correct?
#5
Posted 11 April 2006 - 08:03 AM
I'll stick with enumerating the registry.
This is what I would use based on AutoIt3
Edit:
Rude of me to forget, thanks for your reply, RogueSpear
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
This post has been edited by MHz: 11 April 2006 - 08:07 AM
#6
Posted 11 April 2006 - 09:14 AM
@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.
#7
Posted 11 April 2006 - 09:40 AM
RogueSpear, on Apr 12 2006, 01:14 AM, said:
@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
Share this topic:
Page 1 of 1



Help
Back to top









