Jump to content

Delete registry key only if its empty


Go to solution Solved by supraspecies,

Recommended Posts

Posted

Hi. Just as topic name says, I need to delete registry key only if its empty. There is this topic:

But no, I don't know all the values that would possibly exist in this key. So any other way?

  • Solution
Posted (edited)

Yes, thanks. Was able to come up with a solution:

RegEnumKey ('HKCU\Software\techPowerUp', 1)
$nokeys=(@error=-1)
RegEnumVal ('HKCU\Software\techPowerUp', 1)
$novalues=(@error=-1)
If $nokeys And $novalues Then RegDelete ('HKCU\Software\techPowerUp') 

I was trying to delete empty "techPowerUp" key. With the above code, it deletes only if there are no keys and values in it. Let the code be here for anyone who needs it since I wasn't able to find an answer when I searched.

Edited by supraspecies

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...