Jump to content
Sign in to follow this  
MariusN

function deletes "some" registry entries...not all

Recommended Posts

MariusN

Hi folks. I have a "very" small script that apparently doesnt want to delete ALL ( only 4 sub-keys ) even though i have a "for 1 to 20" in my script-line...any ideas?

#RequireAdmin
Local $I, $reg2, $del


For $I = 1 To 20 
    $reg2 = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\", $I)
    
        MsgBox(0,"",@error)
    
        $del = RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" & $reg2)
Next

You will notice the "@error" that i placed to try and help me out...i get two "0"...then a "-1"...then "1" as an error. Funny thing is though...If i run this script about 3x, it delete everything i want it to...

 

Here is my REAL code:

#RequireAdmin
Local $I, $reg2, $del


For $I = 1 To 20
    $reg2 = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\", $I)
    If @error <> 0 Then ExitLoop

    $del = RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" & $reg2)
Next
Edited by MariusN

Share this post


Link to post
Share on other sites
Spiff59

I thought for a moment that relying upon @error = 0 might be a mistake as it's not documented anywhere that a 0 is returned.

But it appears to be much less fun than that... are we missing a comma between the RegDelete() parameters?

Edit: There's more to this than first meets the eye...

Edit2: I have the following 4 keys beneath the "972" key you reference:

  {718BB738-AA76-4BE1-AB9B-C4DA931A4B4D}

  {9B79FBA7-7082-4276-80E8-D7C8F3C732B2}

  {F4746EE5-DA79-4CEB-92D6-AB2E3F2A8E37}

  Descriptions

When I run the following, I seem to get the results I'd expect out of RegEnumKey, but not RegEnumVal...

#RequireAdmin
Local $key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"
Local $I, $reg2, $del, $err1, $err2

For $I = 1 To 5
    $reg1 = RegEnumKey($key, $I)
    $err1 = StringRight("  " & @error, 2)
    $reg2 = RegEnumVal($key, $I)
    $err2 = StringRight("  " & @error, 2)
        ConsoleWrite("$I = " & $I & @CRLF & "  @error = " & $err1 & "  key = " & $reg1 & @CRLF & "  @error = " & $err2 & "  val = " & $reg2 & @CRLF)
;   $del = RegDelete($key" & $reg1)
Next

The $I=2 iteration for subkey   {718BB738-AA76-4BE1-AB9B-C4DA931A4B4D} returns a val of "Class" and @error = 0.

Iterations 3 and 4 for {9B79FBA7-7082-4276-80E8-D7C8F3C732B2} and {F4746EE5-DA79-4CEB-92D6-AB2E3F2A8E37} return no val string and both receive an @error = -1.  Yet the structure for all 3 keys appears to be identical.

Sorry I wasn't of any help.

Edited by Spiff59

Share this post


Link to post
Share on other sites
MariusN

...not that i can see though...i have trie comma's, @error = -1....@error = 1...etc

UNLESS...something in windows itself is preventing me...I have even checked the "ownership"...and everything seems ok...

Edited by MariusN

Share this post


Link to post
Share on other sites
MariusN

How many subkeys remain?

My guess would be you are deleting keys 1, 3, 5 and 7 ...right?

Jos

100% correct Jos....

Share this post


Link to post
Share on other sites
MariusN

Geez...I had to do this....thx for the 1-3-5 tip though :sorcerer:

For $i = 1 To 20 step 1
    $reg2 = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\", $i)
    If @error <> 0 Then ExitLoop

    $del = RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"& $reg2)
    $i = $i - 1
Next

Share this post


Link to post
Share on other sites
MariusN

 

Geez...I had to do this....thx for the 1-3-5 tip though :sorcerer:

For $i = 1 To 20 step 1
    $reg2 = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\", $i)
    If @error <> 0 Then ExitLoop

    $del = RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"& $reg2)
    $i = $i - 1
Next

Tell me Jos...Is this normal, or was it something to do with my way of "coding"?

Share this post


Link to post
Share on other sites
Jos

Just use this line:

$reg2 = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\", 1)

.. and it is all about logic.

RegEnumKey() retrieves the Xth key. When you retrieve the 1st key and then delete it, which make the original 2nd key now the 1st.

That is why you need to keep retrieving the 1st key name and deleting it.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
MariusN

Just use this line:

$reg2 = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\", 1)

.. and it is all about logic.

RegEnumKey() retrieves the Xth key. When you retrieve the 1st key and then delete it, which make the original 2nd key now the 1st.

That is why you need to keep retrieving the 1st key name and deleting it.

Jos

o ok...thanks Jos....much appreciate :geek:

Share this post


Link to post
Share on other sites
Spiff59

While 1
     $reg2 = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\", 1) 
     If @error Then ExitLoop
     $del = RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" & $reg2)
Wend

I guess that would be the simplest?

I am still confused at the results RegEnumVal give me in the post #2 example above...

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  

×