Jump to content

IsInstalled


dufran3
 Share

Recommended Posts

Super simple UDF, I'm sure someone has created something similar, and better I'm sure. But this worked for me, just wanted to share it with everyone. All it does is check to see if an application is installed by searching the registry for the "application name" as it appears in Add/remove programs.

;===============================================================================
;
; Function Name:    _IsInstalled()
; Description:      Checks to see if application is installed
; Parameter(s):     $s_String       - Required: Application name to search for, !!Must be exactly as it appears in Add/Remove Programs
; Requirement(s):   AutoIt3 V3.2 or higher
; Return Value(s):  On Success  - Sets global "$IsInstalled" varibale to 1
;                   On Failure  - Sets global "$IsInstalled" varibale to 0
; Author(s):        ***
;===============================================================================

Func _IsInstalled($s_String)
    $searchpath = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
    $valuename = 'DisplayName'
    $IsInstalled = 0
    For $i= 1 to 10000
        $currentkey = RegEnumKey($searchpath, $i)
        If @error <> 0 then ExitLoop

        $displayname = RegRead($searchpath & "\" & $currentkey, $valuename)
        
        If $displayname ==  $s_String Then
            GLOBAL $IsInstalled = 1
        Else
        EndIf
    Next
EndFunc
Edited by dufran3
Link to comment
Share on other sites

well, nice job.

heres a more standard UDF (User Defined Function) layout if your interested

;example
Local $program = 'AutoIt v3.2.2'
Local $IsInstalled = _IsInstalled($program)
Msgbox(0, $program & ' is installed', $IsInstalled=1)

;===============================================================================
;
; Function Name:    _IsInstalled()
; Description:      Checks to see if application is installed
; Parameter(s):     $s_String      - Required: Application name to search for, !!Must be exactly as it appears in Add/Remove Programs
; Requirement(s):   AutoIt3 V3.2 or higher
; Return Value(s):  On Success  - Sets global "$IsInstalled" varibale to 1
;                   On Failure  - Sets global "$IsInstalled" varibale to 0
; Author(s):        Kevin Sanders
;===============================================================================


Func _IsInstalled($s_String)
    Local $searchpath = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
    Local $valuename = 'DisplayName'
    For $i = 1 to 10000
        $currentkey = RegEnumKey($searchpath, $i)
        If @error then ExitLoop
        $displayname = RegRead($searchpath & "\" & $currentkey, $valuename)
        If $displayname == $s_String Then
            Return 1
        EndIf
    Next
    Return 0
EndFunc
Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
Link to comment
Share on other sites

well, nice job.

heres a more standard UDF (User Defined Function) layout if your interested

;example
Local $program = 'AutoIt v3.2.2'
Local $IsInstalled = _IsInstalled($program)
Msgbox(0, $program & ' is installed', $IsInstalled=1)

;===============================================================================
;
; Function Name:    _IsInstalled()
; Description:      Checks to see if application is installed
; Parameter(s):     $s_String      - Required: Application name to search for, !!Must be exactly as it appears in Add/Remove Programs
; Requirement(s):   AutoIt3 V3.2 or higher
; Return Value(s):  On Success  - Sets global "$IsInstalled" varibale to 1
;                   On Failure  - Sets global "$IsInstalled" varibale to 0
; Author(s):        Kevin Sanders
;========  =======================================================================
Func _IsInstalled($s_String)
    Local $searchpath = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
    Local $valuename = 'DisplayName'
    For $i = 1 to 10000
        $currentkey = RegEnumKey($searchpath, $i)
        If @error then ExitLoop
        $displayname = RegRead($searchpath & "\" & $currentkey, $valuename)
        If $displayname == $s_String Then
            Return 1
        EndIf
    Next
    Return 0
EndFunc
If you change the script then you should have changed the comments to match.

; Return Value(s): On Success - returns 1

; On Failure - returns 0

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

The reason I don't use Return, is because I'm not sure how to read from it. I know that if I set the GLOBAl variable $IsInstalled =1, then I know I can say, If $IsInstalled == 1 Then "Do This". I"m not sure how to evaluate what the function returned...

Edit: Nevermind, now I see from your example....Local $IsInstalled = _IsInstalled($program)

Edited by dufran3
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
 Share

  • Recently Browsing   0 members

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