Jump to content

While / If loop not working as expected


Go to solution Solved by scubar,

Recommended Posts

Hi Guys

Ive been a long time browser of these forums and have managed to create many basic scripts using the information here but I have come across a problem with my latest one.

Im trying to loop through a reg key to remove any left over traces of Adobe Reader but for some reason it deletes some but leaves other entries. If I run the script again it will then delete some more. 

I would like it to be able to run once and catch all the entries and remove them. Below is the code im using.

Any help would be greatly appreciated

; Checks the Registry and removes any left over Adobe reader entries
Local Const $sSKey0 = "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products"
Local $a, $sSubKey0, $RegKey0,$ProductName, $Found
$ProductName = ""
$Found = ""
While 1
$a += 1
$sSubKey0 = RegEnumKey($sSKey0, $a)
If @Error Then ExitLoop
$ProductName = RegRead($sSKey0 & "\" & $sSubKey0, "ProductName")
If StringInStr($ProductName, "Adobe Reader 9") Or _
StringInStr($ProductName, "Adobe Reader X") Or _
StringInStr($ProductName, "Adobe Reader XI") Then
$RegKey0 = $sSKey0 & "\" & $sSubKey0
RegDelete($RegKey0)
EndIf
Sleep(100)
WEnd

Heres the registry entries im using for testing. It seems to leave the Adobe Reader 9.1 , Adobe Reader X and Adobe Reader XI on first run. Subsequent runs then remove these keys.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\68AB67CA7DA73301B7449A0000000010]
"Clients"=hex(7):3A,00,00,00,00,00
"Version"=dword:09000000
"Language"=dword:00000409
"Assignment"=dword:00000001
"PackageCode"="83AA9F33BAE0DC849BB8A5FF1750CF28"
"ProductIcon"="C:\\WINDOWS\\Installer\\{AC76BA86-7AD7-1033-7B44-A90000000001}\\SC_Reader.exe"
"ProductName"="Adobe Reader 9"
"InstanceType"=dword:00000000
"AdvertiseFlags"=dword:00000184
"AuthorizedLUAApp"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\68AB67CA7DA73301B7449A0100000010]
"Clients"=hex(7):3A,00,00,00,00,00
"Version"=dword:09010000
"Language"=dword:00000409
"Assignment"=dword:00000001
"PackageCode"="99B7519FD0484DE4FB163EC4B8907265"
"ProductIcon"="C:\\WINDOWS\\Installer\\{AC76BA86-7AD7-1033-7B44-A91000000001}\\SC_Reader.ico"
"ProductName"="Adobe Reader 9.1"
"InstanceType"=dword:00000000
"AdvertiseFlags"=dword:00000184
"AuthorizedLUAApp"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\68AB67CA7DA73301B7449A0500000010]
"Clients"=hex(7):3A,00,00,00,00,00
"Version"=dword:09050000
"Language"=dword:00000409
"Assignment"=dword:00000001
"PackageCode"="EE1AFE940DEE28F48AF671209DA086CF"
"ProductIcon"="C:\\WINDOWS\\Installer\\{AC76BA86-7AD7-1033-7B44-A95000000001}\\SC_Reader.ico"
"ProductName"="Adobe Reader 9.5.0"
"InstanceType"=dword:00000000
"AdvertiseFlags"=dword:00000184
"AuthorizedLUAApp"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\68AB67CA7DA73301B744AA0000000010]
"Clients"=hex(7):3A,00,00,00,00,00
"Version"=dword:0A000000
"Language"=dword:00000409
"Assignment"=dword:00000001
"PackageCode"="A9AC7483F9E553B43A2FB0E9E01FA346"
"ProductIcon"="C:\\WINDOWS\\Installer\\{AC76BA86-7AD7-1033-7B44-AA0000000001}\\SC_Reader.ico"
"ProductName"="Adobe Reader X"
"InstanceType"=dword:00000000
"AdvertiseFlags"=dword:00000184
"AuthorizedLUAApp"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\68AB67CA7DA73301B744AA0100000010]
"Clients"=hex(7):3A,00,00,00,00,00
"Version"=dword:0A010004
"Language"=dword:00000409
"Assignment"=dword:00000001
"PackageCode"="01E1AB89E10D8F44CA00643AFEEF80FC"
"ProductIcon"="C:\\WINDOWS\\Installer\\{AC76BA86-7AD7-1033-7B44-AA1000000001}\\SC_Reader.ico"
"ProductName"="Adobe Reader X (10.1.4)"
"InstanceType"=dword:00000000
"AdvertiseFlags"=dword:00000184
"AuthorizedLUAApp"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\68AB67CA7DA73301B744BA0000000010]
"Clients"=hex(7):3A,00,00,00,00,00
"Version"=dword:0B000000
"Language"=dword:00000409
"Assignment"=dword:00000001
"PackageCode"="A98DAC519B3390444B1480C824EC0845"
"ProductIcon"="C:\\WINDOWS\\Installer\\{AC76BA86-7AD7-1033-7B44-AB0000000001}\\SC_Reader.ico"
"ProductName"="Adobe Reader XI"
"InstanceType"=dword:00000000
"AdvertiseFlags"=dword:00000184
"AuthorizedLUAApp"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\68AB67CA7DA73301B745BA0000000010]
"Clients"=hex(7):3A,00,00,00,00,00
"Version"=dword:0B000003
"Language"=dword:00000409
"Assignment"=dword:00000001
"PackageCode"="A48771085A49DA04EA844D06042E0AC0"
"ProductIcon"="C:\\WINDOWS\\Installer\\{AC76BA86-7AD7-1033-7B44-AB0000000001}\\SC_Reader.ico"
"ProductName"="Adobe Reader XI (11.0.03)"
"InstanceType"=dword:00000000
"AdvertiseFlags"=dword:00000184
"AuthorizedLUAApp"=dword:00000000
Edited by scubar
Link to comment
Share on other sites

You are incrementing $a every time - even after deleting a reg key. I'm not familar with AutoIt registry functions, but I think this is the most likely cause of your problem. Once a key is deleted, I would imagine the remaining keys are assigned new numeric values.

Edit : I could be wrong, but the problem you describe fits with kind of results I'd expect.

Edited by czardas
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...