Sign in to follow this  
Followers 0
supraspecies

Delete registry key only if its empty

4 posts in this topic

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?

Share this post


Link to post
Share on other sites



#3 ·  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

Share this post


Link to post
Share on other sites

Please mark the topic as "Solved" for everyone else to know.

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  
Followers 0