Archive: DeleteRegKey?


Is there a way to remove a certain registry key on the condition that it's completely empty?

Say I have this layout:

HKCU\Software\Alex\Program

which is createed on install.

On uninstall, I will DeleteRegKey that key, but I can't delete Alex just in case other programs by this particular author are installed.

And I'd prefer not to leave it there. I personally hate empty keys under Software.


Don't think so, because DeleteRegKey is recursive nowadays... Don't really like that, there should be an option /r or something which controls this.


Hi guys,

I actually suggest such modifications for a few times but never got a response. What is really needed are methods to 1. check if a key contains
a) any values
b) any subkeys
2. retrieve the names of
a) the values
b) the subkeys

Snowbird


hi,

why don't you just read the keys (ReadRegKey), compare them (StrCmp)and if they aren't empty remove them (DeleteRegKey).

what has that to do with recursive?
if you don't want do delete a special key you don't have to, do you?

cu yzo


Thanks, yzo, but is there a way to just check if any stuff exists under the key? I couldn't see if something specific is there, because if that specific something isn't there and other stuff is, boom.


hi,

when i remove a key i know what i delete, because i wrote it there, so i know which value i have to read and compare before deleting.

if you aren't sure, why would you want to delete a regkey
which you don't know if it is empty or usefull with your installer?

why don't you use DeleteRegValue instead?

cu yzo


Okay, well, I install to

HKCU\Software\Alex\ProgramA

and on uninstall, I delete

HKCU\Software\Alex\ProgramA

I would like to be able to also delete

HKCU\Software\Alex

but I can't just in case this user has installed another program:

HKCU\Software\Alex\ProgramB

And I don't particularly wish to leave an empty Alex key behind. I'd prefer a completely clean install.

Snowbird, I agree with you on 1. a) b). But I believe 2. a) b) can be done now.


hi,

if you write a key to HKCU\Software\Alex\ProgramA

you should know other possible keys under HKCU\Software\Alex\ ( 'cause it seems like you were Alex ;) )

HKCU\Software\Alex\ProgramB
HKCU\Software\Alex\ProgramC
HKCU\Software\Alex\ProgramD

so you could check for them, couldn't you?

cu yzo


But you don't know right now which programs you are going to write in the future, so you don't know the names of ProgramC and ProgramD :)

Just my idea.


hi,

LOL .. sure.
yeah koen you are right, i didn't think of that .. uhh ..

so ReadRegValues would be quite useful!

cu yzo


How do you think it is possible now to discover the names of the values? I don't think this is possible. Maybe I have to be more precise: I want to obtain a list containing all the names of the values/subkeys.

A problem I see here with respect to the implementation is that NSIS doesn't know any list data type. However, the following should be possible to implement:
1. FirstRegValueName HKEY SUBKEY $x
Will retrieve the name of the first value in SUBKEY and write it to $x or throw an error if there is none.
2. NextRegValueName HKEY SUBKEY $x
Will retrieve the next name and write it to $x or throw an error if there is none.

I implemented some C functions to do this, however I never had a look at the NSIS source code, so I don't feel fit to hack this into NSIS. Anyone feeling fit to do so who wants the code, please let me know.

Snowbird