Jump to content

Delete Registry Keys


Docfxit
 Share

Recommended Posts

I have a script that I think I have a few problems with.

The first problem is in my For $x loop.  It isn't executing the For statement.

; Delete all registry keys in .reg file
;
#RequireAdmin
#include <file.au3>
#include "ExtMsgBox.au3"
Dim $MyArrayVariable, $MsgBoxText, $x
$FileToRead = "D:\Dnload\%Test\SuperSpeed.reg"
; Read reg file into array
If _FileReadToArray($FileToRead, $MyArrayVariable) Then
    For $i = 1 To $MyArrayVariable[0]
        $MsgBoxText = $MsgBoxText & $i & " " & $MyArrayVariable[$i] & @CRLF
    Next
Else
    ; returncode was 0 so the function reported that the file doesn't exist
    MsgBox(0, "Error", "File Doesn't exist - " & $FileToRead)
EndIf

For $x = ($i - 1) To 1 Step -1
    If StringLeft($MyArrayVariable[$x], 5) = "[Hkey" Then
        _DeleteKey($MyArrayVariable[$x])
    EndIf
Next
Exit

Func _DeleteKey($RegistryEntry)
    Local $SetACL_On = "C:\Batch\SetACL.exe -on"
    Local $SetACL_Owner = ' -ot reg -actn setowner -ownr "n:Administrators"'
    Local $SetACL_AddPermissions = ' -ot reg -actn ace -ace "n:Administrators;p:full'
    Local $RegistryEntry1 = StringTrimRight($RegistryEntry, 1) ; Remove the ] rightmost character from the string.
    Local $RegistryEntry2 = StringTrimLeft($RegistryEntry1, 1) ; Remove the [ leftmost character from the string.
    Local $RegistryEntry3 = '"' & $RegistryEntry2 & '"'  ; Remove the [ leftmost character from the string.
    _ExtMsgBoxSet(1 + 32 + 64, 1, 0x0DF4E8, 0, 11, "Nyala", @DesktopWidth - 20)
    $sMsg = @ComSpec & " /c " & $SetACL_On & " " & $RegistryEntry3 & " " & $SetACL_Owner
    ;AutoIt_Debugger_Command:Enable_Debug
    $iRetValue = _ExtMsgBox(0, " ", "Please Wait for 10 seconds", $sMsg, 10, 400, 400)
    RunWait(@ComSpec & ' /k ' & $SetACL_On & " " & $RegistryEntry3 & " " & $SetACL_Owner, "", @SW_MAXIMIZE)
    RunWait(@ComSpec & " /k " & $SetACL_On & " " & $RegistryEntry3 & " " & $SetACL_AddPermissions, "", @SW_MAXIMIZE)
    Sleep(3000)
    ;RegDelete($RegistryEntry3)
    ;AutoIt_Debugger_Command:Disable_Debug
EndFunc   ;==>_DeleteKey

Thank you,

Docfxit

Edited by Docfxit
Link to comment
Share on other sites

Great suggestion.

I'm now having a problem with this line:

If $MyArrayVariable[$x] = "[Hkey" Then

I would like it to match only on the first 5 characters.

The entire line looks like this:

[HKEY_LOCAL_MACHINESYSTEMControlSet001EnumSWControl]

Thank you,

Docfxit

Edited by Docfxit
Link to comment
Share on other sites

If StringLeft($MyArrayVariable[$x], 5) = "[Hkey"

That works really great.

Thank you.

I am now finding out this isn't working.

RunWait(@ComSpec & " /c " & $SetACL_On & " " & $RegistryEntry & " " & $SetACL_AddPermissions, "", @SW_HIDE)

I did add #RequireAdmin

I have added a msgbox to prove the SETACL has the correct text and spacing.

I don't know what else to try.

 

Thanks,

Docfxit

Edited by Docfxit
Link to comment
Share on other sites

  • Moderators

Seriously?  Is anything working from before?

Try debugging it, show what you tried, then post.  Not right having others go through your entire script fixing issues you haven't debugged or attempted to find solutions for yourself.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I currently have a mess.  I'm sure there must be an easier way to do this.

This is what I started:

Local $RegistryEntry1 = StringTrimRight($RegistryEntry, 1) ; Remove the ] rightmost character from the string.
Local $RegistryEntry2 = StringTrimLeft($RegistryEntry1, 1) ; Remove the [ leftmost character from the string.
Local $RegistryEntry3 = """ & $RegistryEntry2 & """  ; Add Quotes to the string.

The $RegistryEntry starts with this: [HKEY_LOCAL_MACHINESYSTEMControlSet002EnumSW1&79f5d87&0&0001]

I removed the brackets on the left and right.

I need to add a quote on either side of the registry key.

What $RegistryEntry3 currently has is " $RegistryEntry2 "

What is should be is: "HKEY_LOCAL_MACHINESYSTEMControlSet002EnumSW1&79f5d87&0&0001"

So I need to figure out how to resolve the variable and remove the spaces before and after the registry entry.

Thanks,

Docfxit

Edited by Docfxit
Link to comment
Share on other sites

  • Moderators

'"' & $sVar & '"'

Or you were close:

"""" & $sVar & """"

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I'm getting this error when I run it:

ERROR in command line: Invalid option specified: -!

Type 'SetACL -help' for help.

This is what the cmd line looks like:

C:Windowssystem32cmd.exe /c C:BatchSetACL.exe -on "HKEY_LOCAL_MACHINESYSTEMControlSet001EnumSWDiskSuperSpeed_RamDisk_9_01&1a590e2c&0&0001LogConf"  - ot reg - actn setowner - ownr "n:Administrators"

Note:  It's all on one line.

Thanks,

Docfxit

Link to comment
Share on other sites

Well, not that this has anything to do with AutoIt any more, but ok... The error message is pretty clear! Option "-" is not a valid option, yet you try to use it three times. By the way, the way you wrote it now, there's a lot more invalid options. "-" is just the first one it finds.

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Well, not that this has anything to do with AutoIt any more, but ok... The error message is pretty clear! Option "-" is not a valid option, yet you try to use it three times. By the way, the way you wrote it now, there's a lot more invalid options. "-" is just the first one it finds.

Thanks for pointing that out.  I wasn't able to see that.

I discovered the problem was I had a space between the "-" and the option.  The "-" belongs there in front of the option. The samples I found on the internet had the space also.

You mentioned "By the way, the way you wrote it now, there's a lot more invalid options. "-" is just the first one it finds."

I have corrected the "-" option.  It seems to run.  What other invalid options are you seeing?

Thank you very much,

Docfxit

Link to comment
Share on other sites

  • Moderators

What other invalid options are you seeing?

 

In reading through this thread from the beginning, I have yet to see an ounce of troubleshooting come from you, only vague questions of "this is the problem, help please" variety.

SadBunny stated you have other invalid options when calling SetACL, instead of asking the above, why don't you try Googling SetACL, and see for yourself?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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