Jump to content

Regdelete issue using RegEnumVal


Recommended Posts

Hi, I am searching for a string in a predefined regkey and once found (one or more instance), I am trying to get it deleted but having no success in deleting the key(s). The script I am using is from the below link.

Recursive Registry Search Help

Trimmed code is (original code thanks to PSaltyDS):

$SearchKey = "HKEY_CURRENT_USER\Software\metapad"
$SearchString = "mru"

$Results = _RegSearch($SearchKey, $SearchString)
MsgBox(64, "Results", "ClassGUID for " & $SearchString & " is: " & $Results)
RegDelete($SearchKey & "\" & $Results)

Func _RegSearch($startkey, $searchval)
    Local $v, $val, $k, $key, $found = ""
   
    $v = 1
    While 1
        $val = RegEnumVal($startkey, $v)
        If @error = 0 Then
          
            If StringInStr($val, $searchval) Then
                $found = $found & $startkey & "\" & $val & @LF
               ;RegDelete($SearchKey & "\" & $val)
            EndIf
            
            $readval = RegRead($startkey, $val)
            If StringInStr($readval, $searchval) Then
                $found = $found & $startkey & "\" & $val & " = " & $readval & @LF
            EndIf
            
            $v += 1
        Else
           ; No more values here
            ExitLoop
        EndIf
    WEnd
      
    Return $found
EndFunc  ;==>_RegSearch

I have also tried RegDelete($SearchKey & ',' & '"' & $val & '"') but doesn't work.

(I believe above, assuming my string is mru_8, translates to: RegDelete("HKEY_CURRENT_USER\Software\metapad", "mru_8")

However if you run this line on its own, it works fine:

RegDelete("HKEY_CURRENT_USER\Software\metapad", "mru_8")

What am I doing wrong? Can someone point me in the right direction please?

Link to comment
Share on other sites

When using RegDelete, you will notice you get return values. Run RegDelete inside a MsgBox to see the return value. That should give you some direction. Also, You could do a RegRead to check to see if the value is really there first, and run that inside a MsgBox to check.

Link to comment
Share on other sites

Thanks for the suggestion Volly,

Here is a version of above code modified with getting the return value of the Reddelete (noticed I made some errors in earlier code). Unfortunately the return code is '0' and this means the Key/Value does not exist. However the Name key definitely exists as I can see it via regedit and I have it refreshed too. Moreover when running this line on its own, it works fine:

RegDelete("HKEY_CURRENT_USER\Software\metapad", "mru_8")

$SearchKey = "HKEY_CURRENT_USER\Software\metapad"
$SearchString = "mru_8"

_RegSearch($SearchKey, $SearchString)


Func _RegSearch($SearchKey, $SearchString)
    Local $v, $val, $found = ""
   
    $v = 1
    While 1
        $val = RegEnumVal($SearchKey, $v)
        If @error = 0 Then
          
            If StringInStr($val, $SearchString) Then
                               
                MsgBox(64, "Going to delete(1): ", '"' & $SearchKey & '"' & ',' & '"' & $val & '"')
                $a = RegDelete('"' & $SearchKey & '"' & ',' & '"' & $val & '"')
                MsgBox(64, "Return Value", $a)
                
                MsgBox(64, "Going to delete(2): ", $SearchKey & ',' & $val)
                $b = RegDelete($SearchKey & ',' & $val)
                MsgBox(64, "Return Value", $b)
                
           EndIf
            
            $v += 1
            
        Else
          ; No more values here
            ExitLoop
        EndIf
    WEnd

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