Help - Search - Members - Calendar
Full Version: Checking for existing/prior versions
MSFN Forums > Unattended Windows Discussion & Support > Application Installs

   


Google Internet Forums Unattended CD/DVD Guide
lamaslany
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
RogueSpear
CODE
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
MHz
Hey RogueSpear,

That VBS using WMI would not work at T-12 (Cmdlines.txt) , correct? huh.gif
RogueSpear
Indeed it would not.
MHz
I'll stick with enumerating the registry.

This is what I would use based on AutoIt3
CODE
$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
RogueSpear
@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.
MHz
QUOTE (RogueSpear @ Apr 12 2006, 01: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.

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 newwink.gif

Add code here for comparison.
CODE
$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




Google Internet Forums Unattended CD/DVD Guide

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.