Jump to content

Registry Related Question


Recommended Posts

Something like this maybe?

Dim $s_Root = 'HKEY_LOCAL_MACHINE\SOFTWARE\MyProg'
Dim $i_Key = 1, $s_Key = RegEnumKey($s_Root, $i_Key)
While not @Error
$s_Val = RegEnumVal($s_Root & '\' & $s_Key, 1)
If @error Then RegDelete($s_Root & '\' & $s_Key)
$i_Key += 1
$s_Key = RegEnumKey($s_Root, $i_Key)
WEnd

Basically you're wanting to go through all the keys in a particular key and remove any that do not have values. Is that correct?

Edited by blindwig
Link to comment
Share on other sites

So, let's recap on what you would like to do.

If app2 is empty or not there
   remove app1
Else
   remove myprog
EndIf

And, you are having problems on detecting on whether a key is empty.

(If only got (default), then considered empty, right?)

Solution:

If _IsRegKeyEmpty ("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2") = 1 Then
RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1")
Else
RegDelete("HKEY_CURRENT_USER\Software\MyProg")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")
EndIf

Func _IsRegKeyEmpty($regkey)
   Dim $i_Key = 1, $s_Key = RegEnumKey($regkey, $i_Key)
   While not @Error
      If Not ($s_Key = "" Or $s_Key = "(default)") Then Return 0;;not empty
      $i_Key += 1
      $s_Key = RegEnumKey($regkey, $i_Key)
   WEnd
   Return 1;;empty
EndFunc

Not tested...

#)

EDIT: more typos

Edited by nfwu
Link to comment
Share on other sites

thanks nfwu, got it working using your approuch :)

the actual purpose was to delete the MyProg key if nothing else was in it...here is the final script:

Func _IsRegKeyEmpty($regkey)
   Dim $i_Key = 1, $s_Key = RegEnumKey($regkey, $i_Key)
   While not @Error
      If Not ($s_Key = "" Or $s_Key = "(default)") Then Return 0;;not empty
      $i_Key += 1
      $s_Key = RegEnumKey($regkey, $i_Key)
   WEnd
   Return 1;;empty
EndFunc

; Clean App1 Settings
RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1") 
; Clean MyProg Settings if empty
if not _IsRegKeyEmpty("HKEY_CURRENT_USER\Software\MyProg") = 0 then
;  other appz do not exist, so here it removes the whole key
    RegDelete("HKEY_CURRENT_USER\Software\MyProg")
    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")
endif
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...