Batcher

RegDelete via FileReadLine does not work

7 posts in this topic

#1 ·  Posted

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 :-)

Share this post


Link to post
Share on other sites



#2 ·  Posted

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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#3 ·  Posted

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#5 ·  Posted

You made my day, thank you so much!
Normally i'm really familiar scripting things in whatever language... now i'm just ashamed :>

Thank you :lol:

Share this post


Link to post
Share on other sites

#6 ·  Posted

@Batcher

Happy to have helped!

And... Don't be ashamed! Everyone makes some error 'cause of distraction :)

Have a good day! :)


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#7 ·  Posted

:thumbsup:

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