Jump to content
Sign in to follow this  
bourny

Is a program installed ?

Recommended Posts

bourny

I am looking to determine if a program is installed on my system. I usually check by looking at

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{GUID ID} \DisplayName

This works fine if I know the GUID will stay the same. In my current case there is a good possibility the product will change its GUID and result in my script triggering an update even though the product is installed just under a different GUID,

I have 2 ideas that I dont know how to tackle to work around this issue

1. Output all Guids/keys in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ and look thru each display name for the presence of my product name - If it is picked up in any other GUID that I know the GUID hasd changed and to abort the program

2. Somehow other than the registry check the system for the precense of a program called "MY PROGRAM" is installed (Mabe using API / objects etc)

Any help appreciated

Share this post


Link to post
Share on other sites
SpookMeister

Here is a modified snippet of code I used once, it may give you an idea of how to work with your first workaround.

#include <array.au3>
$a_software=_InstalledSoftware()
_ArrayDisplay($a_software)
Func _InstalledSoftware()
    Local $Count = 1
    Local Const $regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

    While 1
        $key = RegEnumKey($regkey, $Count)
        If @error <> 0 Then ExitLoop
        ConsoleWrite($key & @CRLF)
        $line = RegRead($regkey & '\' & $key, 'DisplayName')
        $line = StringReplace($line, ' (remove only)', '')
        If $line <> '' Then
            If Not IsDeclared('avArray') Then Dim $avArray[1][5]
            ReDim $avArray[UBound($avArray) + 1][5]
            $avArray[0][0] = UBound($avArray) - 1
            $avArray[UBound($avArray) - 1][0] = $line
            $avArray[UBound($avArray) - 1][1] = RegRead($regkey & '\' & $key, 'DisplayVersion')
            $avArray[UBound($avArray) - 1][2] = RegRead($regkey & '\' & $key, 'InstallDate')
            $avArray[UBound($avArray) - 1][3] = RegRead($regkey & '\' & $key, 'Publisher')
            $avArray[UBound($avArray) - 1][4] = $key
        EndIf
        $Count = $Count + 1
    WEnd
    If Not IsDeclared('avArray') Then
        SetError(1)
        Return ('')
    Else
        SetError(0)
        
        Return ($avArray)
    EndIf
EndFunc   ;==>_InstalledSoftware

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
bourny

Here is a modified snippet of code I used once, it may give you an idea of how to work with your first workaround.

#include <array.au3>
$a_software=_InstalledSoftware()
_ArrayDisplay($a_software)
Func _InstalledSoftware()
    Local $Count = 1
    Local Const $regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

    While 1
        $key = RegEnumKey($regkey, $Count)
        If @error <> 0 Then ExitLoop
        ConsoleWrite($key & @CRLF)
        $line = RegRead($regkey & '\' & $key, 'DisplayName')
        $line = StringReplace($line, ' (remove only)', '')
        If $line <> '' Then
            If Not IsDeclared('avArray') Then Dim $avArray[1][5]
            ReDim $avArray[UBound($avArray) + 1][5]
            $avArray[0][0] = UBound($avArray) - 1
            $avArray[UBound($avArray) - 1][0] = $line
            $avArray[UBound($avArray) - 1][1] = RegRead($regkey & '\' & $key, 'DisplayVersion')
            $avArray[UBound($avArray) - 1][2] = RegRead($regkey & '\' & $key, 'InstallDate')
            $avArray[UBound($avArray) - 1][3] = RegRead($regkey & '\' & $key, 'Publisher')
            $avArray[UBound($avArray) - 1][4] = $key
        EndIf
        $Count = $Count + 1
    WEnd
    If Not IsDeclared('avArray') Then
        SetError(1)
        Return ('')
    Else
        SetError(0)
        
        Return ($avArray)
    EndIf
EndFunc   ;==>_InstalledSoftware

Excellent - Seems I missed the "RegEnumKey". This is exactly what I need ...

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.