Jump to content

RegDelete via FileReadLine does not work


Recommended Posts

Greetings to all listeners,

i've got a program importing lines from a textfile to use with RegDelete.
Is it possible to read lines from a textfile and use RegDelete to remove these imported lines from registry by using RegDelete command?

It works well with:
RegDelete ("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders", "C:\Program Files (x86)\Microsoft Office\Office14\")

If i want to use it with FileReadLine:
RegDelete ("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders", "$RegValue")

Complete script:
Local $File = FileOpen ("InstallerFolders.txt", 0)

If $File = -1 Then
MsgBox (0, "Fehler", "Die Datei konnte nicht geöffnet werden.")
Exit
EndIf

While 1
Local $RegValue = FileReadLine ($File)
If @error = -1 Then ExitLoop
RegDelete ("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders", "$RegValue")
WEnd

FileClose ($File)

I always get Error 1 which says the key/value does not exist but it does.

The contents of InstallerFolders.txt is:
C:\Program Files (x86)\Microsoft Office\MEDIA\OFFICE14\1031\
C:\Program Files (x86)\Microsoft Office\MEDIA\OFFICE14\
...

I nearly searched the whole internet, but couldn't find a hint for this...
Could someone please tell me what i'm doing wrong?

Have a nice day :-)

Link to comment
Share on other sites

Hi @Batcher, and welcome to the AutoIt forum :)

Did you try to see what does the variable $RegValue contain? I would add this code:

While 1
Local $RegValue = FileReadLine ($File)
If @error = -1 Then 
    ExitLoop
Else
    ConsoleWrite("Reg value is: " & $RegValue & @CRLF) ; ----------------------------------> This line
    RegDelete ("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders", "$RegValue")
WEnd

Use the Code ( <> ) tag to insert code in the post, it makes things more readable! :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Hi FrancescoDiMuro,

thanks for your fast reply. Nice hint to show me how to use the console, thank you.
Ok, i tried it your way and it says:

Reg Value is: C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\Office Setup Controller\Office.de-de\
Reg Value is: C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\Office Setup Controller\
Reg Value is: C:\Program Files (x86)\Microsoft Office\Office14\1031\DataServices\
Reg Value is: C:\Program Files (x86)\Microsoft Office\MEDIA\OFFICE14\1031\
...

Just like it should, i think.
I used MsgBox instead of console before to get some information about the $vars. The textfile and it's read-in seams corrent.
The registry also says me "hey, i got the keys and values, try to remove me...". I'm able to remove them directly, with regedit too.
Oh, and i've got admin credentials, that's not the problem.

Link to comment
Share on other sites

@Batcher

You just made a little error, 'cause of distraction! :D

This is what you're trying to do:

RegDelete ("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders", "$RegValue")

And this is what you should do:

RegDelete ("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders", $RegValue)

Spotted the difference?

Simply, you were treating $RegValue as a String, so, the script was using literally the string "$RegValue" as KeyValue instead of "C:\..." ! :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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...