lamaslany Posted April 10, 2006 Share Posted April 10, 2006 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 More sharing options...
RogueSpear Posted April 10, 2006 Share Posted April 10, 2006 Option ExplicitDim ws, fs, strComputer, objWMIService, colSoftware, objSoftwareSet 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 IfNext Link to comment Share on other sites More sharing options...
MHz Posted April 11, 2006 Share Posted April 11, 2006 Hey RogueSpear,That VBS using WMI would not work at T-12 (Cmdlines.txt) , correct? Link to comment Share on other sites More sharing options...
RogueSpear Posted April 11, 2006 Share Posted April 11, 2006 Indeed it would not. Link to comment Share on other sites More sharing options...
MHz Posted April 11, 2006 Share Posted April 11, 2006 (edited) 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) ReturnEndFuncEdit:Rude of me to forget, thanks for your reply, RogueSpear Edited April 11, 2006 by MHz Link to comment Share on other sites More sharing options...
RogueSpear Posted April 11, 2006 Share Posted April 11, 2006 @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. Link to comment Share on other sites More sharing options...
MHz Posted April 11, 2006 Share Posted April 11, 2006 @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) ReturnEndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now