Jump to content
Sign in to follow this  
Ruigerock

@error usage

Recommended Posts

Ruigerock

I just wondered if any if you could think of a smarter way for the following code?

$GoogleEarthN = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{97C0EA4A-1A0B-4C53-ACEB-49984DA79C90}","DisplayName")
$GoogleDesktopN = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Desktop","DisplayName")
$GoogleToolbarN = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{DBEA1034-5882-4A88-8033-81C4EF0CFA29}","DisplayName")
$GoogleNortonN = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7A2ABE01-E182-4045-8F34-972BDE03B4AB}","DisplayName")
$GooglePicasaN = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Picasa2","DisplayName")
$GoogleSpywareN = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Spyware Doctor","DisplayName")
$GoogleSkypeN = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5C82DAE5-6EB0-4374-9254-BE3319BA4E82}","DisplayName")
$GoogleUpdaterN = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Updater","DisplayName")

If $GoogleEarthN = "" And $GoogleDesktopN = "" And $GoogleToolbarN = "" And $GoogleNortonN = "" And $GooglePicasaN = "" And $GoogleSpywareN = "" And $GoogleSkypeN = "" And $GoogleUpdaterN = "" Then
    MsgBox(0,"Google Pack Remover","No Google Pack programs were found on your computer")
    Exit
EndIf

$result = Msgbox(3,"Google Pack Remover","Following programs were found:"&@CRLF&$GoogleEarthN&@CRLF&$GoogleDesktopN&@CRLF&$GoogleToolbarN&@CRLF&$GoogleNortonN&@CRLF&$GooglePicasaN&@CRLF&$GoogleSpywareN&@CRLF&$GoogleSkypeN&@CRLF&$GoogleUpdaterN&@CRLF&@CRLF&"Continue uninstall?")oÝ÷ Ù8^­ë-¡ûazÇ+n)쵩ez×"²z-¦-yÔáz'^jíçâ®Ëij»b²Z()ວ²Ö¥çi®+jk'jg¬jwn±ëaz*çjg¬«^®)íë®*mN|    Ýw@ÔázzZ®Ø¬jYbr¥vØbJjëh×6If Not @error = 0 Then
    MsgBox(0,"Google Pack Remover","No Google Pack programs were found on your computer")
    Exit
EndIf

I thought this would replicate The If...And...And...And...Then part, seems it only checks the last variable $GoogleUpdaterN :)

Who knows a better way??

The second part lists all found programs one after another with an @crlf between each program.

When a program is not found i have a blank rule inserted.

Who knows a better way for a nice looking "no blank rule" list?

Share this post


Link to post
Share on other sites
weaponx

This is how I would do it.

Dim $array[8][3]
$array[0][0] = "Google Earth"
$array[0][1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{97C0EA4A-1A0B-4C53-ACEB-49984DA79C90}"
$array[1][0] = "Google Desktop"
$array[1][1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Desktop"
$array[2][0] = "Google Toolbar"
$array[2][1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{DBEA1034-5882-4A88-8033-81C4EF0CFA29}"
$array[3][0] = "Google Norton"
$array[3][1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7A2ABE01-E182-4045-8F34-972BDE03B4AB}"
$array[4][0] = "Google Picasa"
$array[4][1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Picasa2"
$array[5][0] = "Google Spyware"
$array[5][1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Spyware Doctor"
$array[6][0] = "Google Skype"
$array[6][1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5C82DAE5-6EB0-4374-9254-BE3319BA4E82}"
$array[7][0] = "Google Updater"
$array[7][1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Updater"

$output = ""
$found = false

;Loop through all programs
For $X = 0 to Ubound($array)-1
    $result = RegRead($array[$X][1],"DisplayName")
    If NOT @ERROR Then
        ;If found, set boolean value
        $array[$X][2] = True
        
        ;Set found
        $found = BitOr($found,$array[$X][2])
        
        ;Add program name to output string
        $output &= $array[$X][0] & @CRLF
    EndIf
Next

If NOT $found Then
    MsgBox(0,"Google Pack Remover","No Google Pack programs were found on your computer")
    Exit
EndIf

$result = Msgbox(3,"Google Pack Remover","Following programs were found:" & @CRLF & $output & @CRLF & "Continue uninstall?")

Note:

This line:

$found = BitOr($found,$array[$X][2])

could just be:

$found = True

Same result though.

Edited by weaponx

Share this post


Link to post
Share on other sites
ACS

Here's my method.

[Edit]

Forums are wrapping my lines.

For those lines at the beginning "$GoogleProgs &=" make sure it's one unbroken line including the ending @CRLF.

[Edit2]

weaponx beat me to it. His is a bit nicer because his program is more easily extensible (and more flexible.) Very nice!

$GoogleProgs = ""

; Grab a list of the installed programs
$GoogleProgs &= RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{97C0EA4A-1A0B-4C53-ACEB-49984DA79C90}","DisplayName") & @CRLF
$GoogleProgs &= RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Desktop","DisplayName") & @CRLF
$GoogleProgs &= RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{DBEA1034-5882-4A88-8033-81C4EF0CFA29}","DisplayName") & @CRLF
$GoogleProgs &= RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7A2ABE01-E182-4045-8F34-972BDE03B4AB}","DisplayName") & @CRLF
$GoogleProgs &= RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Picasa2","DisplayName") & @CRLF
$GoogleProgs &= RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Spyware Doctor","DisplayName") & @CRLF
$GoogleProgs &= RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5C82DAE5-6EB0-4374-9254-BE3319BA4E82}","DisplayName") & @CRLF
$GoogleProgs &= RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Updater","DisplayName") & @CRLF

; Eliminate all duplicate CRLFs
While StringInStr($GoogleProgs, @CRLF & @CRLF) > 0
    $GoogleProgs = StringReplace($GoogleProgs, @CRLF & @CRLF, @CRLF)
Wend

; Only a single CRLF means nothing was found so terminate the script
If $GoogleProgs == @CRLF Then
    MsgBox(0,"Google Pack Remover", "No Google Pack programs were found on your computer")
    Exit
EndIf

; Found some programs. Ask the user if they wish to uninstall
$result = Msgbox(3, "Google Pack Remover", "Following programs were found: " & @CRLF & $GoogleProgs & @CRLF & "Continue uninstall?")
Edited by ACS

Share this post


Link to post
Share on other sites
Ruigerock

Thanks weaponx & ACS!

The script made by weaponx is a brainteaser for me.. it took some searching in help and about 20 minutes before i understood the script.

I'm impressed by the way the experts are thinking..

Thanks for learning me some new tricks like array, &= with AutoIT!

Topic can be closed

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  

×