Sign in to follow this  
Followers 0
dreamzboy

Detecting/Find Program in Add/Remove Programs List

5 posts in this topic

Hi,

I'm trying to find a program inside Add/Remove Programs List and return 1 if true (if found), and 0 if false. I used a similar method for finding Microsoft Office 2003 with this statement:

$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Registration", $i)

However, I'm unsuccessful with other programs because I do not know what RegEnumKey is looking for. If someone could tell me what RegEnumKey is looking for maybe I can figure out a way, or, any other method in finding if the program is installed would be a great deal of help.

What I do noticed is that inside the "Registration" Folder it has another folder containing "Registry Key." Using the same logic didn't work because there is no registry folder that look like Microsoft Office inside the program that I'm searching.

Thanks in advance,

-dreamzboy-

Share this post


Link to post
Share on other sites



My first question would be, is this program always to appear in the add/remove programs list? Is it a common program? Most add/remove information is kept here:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

Is your task to remove the program once it finds the information? Installs are put into that section with GUIDs. It is only helpful if you know the GUID you are looking for. They should be the same for all installs for that specific version. Most install programs will generate a new GUID when you make a new version of an installer. Otherwise, you could search on your computer through that folder, get the correct GUID, then have your script look for that.

I hope this is what you mean!

Share this post


Link to post
Share on other sites

Thanks Trip for the reply,

No, it is not a common program. To better explain the tasks that I wanted to do is, if the software is already installed, then activate it, if not, install the program and activate it.

Here's my test program (borrowing from someone here who wrote the function. thanks to that person)

$secure_crt = RegFindUninstallDisplayName("VanDyke Software SecureCRT")
If ($secure_crt[0][1]) Then
    MsgBox(0, "", "System detected SecureCRT is already installed")
Else
    MsgBox(0, "", "SecureCRT is not installed!")
EndIf
    
    
    Func RegFindUninstallDisplayName($sza_DisplayName,$opt = 0)
    Local $i = 0,$j,$n = 1,$key,$val,$uStr
    Local $ret[1][2] = [["",""]]
    
    While 1
        $key = RegEnumKey("HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall",$n)
        If @error = -1 Then ExitLoop
        $n += 1
            If Not @error Then
            $val = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\" & $key,"DisplayName")
            If @error Then ContinueLoop
            $uStr = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\" & $key,"UninstallString")
            If @error Then ContinueLoop
            If IsArray($sza_DisplayName) Then
                For $j = 0 to (UBound($sza_DisplayName) - 1)
                    If (($opt = 0) And StringInStr($val,$sza_DisplayName[$j])) Or _
                            (($opt <> 0) And ($val = $sza_DisplayName[$j])) Then
                        $i += 1
                        Redim $ret[$i][2]
                        $ret[$i-1][0] = $val
                        $ret[$i-1][1] = $uStr
                    EndIf
                Next
            Else
                If (($opt = 0) And StringInStr($val,$sza_DisplayName)) Or _
                        (($opt <> 0) And ($val = $sza_DisplayName)) Then
                    $i += 1
                    Redim $ret[$i][2]
                    $ret[$i-1][0] = $val
                    $ret[$i-1][1] = $uStr
                EndIf
            EndIf
        EndIf
    Wend
    If $ret[0][0] = "" Then Return SetError(1,0,"")
        Return $ret
    EndFunc

Here, I ran into problems. With the program SecureCRT installed on my system, the program do recognize that the software is installed. However, once I removed the program (SecureCRT) and excute the script again, I got an error message pointing me to the statement If ($secure_crt[0][1]) Then. But if I remove the array "[0][1]", the program will then recognize that it's not installed. And if I leave out the array and installed the software again, the program will still say that it's not installed unless I put back the array [0][1]. :)

How would I go about this? Any advice?

Trip, if you suggested that I should look for the directory, what will my function look like? Please excuse my noobieness.

Thanks,

Dreamzboy

Share this post


Link to post
Share on other sites

Does this program have an uninstall.exe that gets installed with it? If so, then have it check for the program exe itself. You wouldn't need to check the registry for the app. Then if you need to uninstall it, have it run the uninstall.exe or whatever the uninstall path from the registry is.

It seems that your main purpose for this program has nothing to do with add/remove programs... Then why bother with its registry entries?

Share this post


Link to post
Share on other sites

Good point. Let me try it and I'll keep you updated.

Thanks.

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  
Followers 0