Delete from Registry using VBA

C

Charlotte E.

Hi Guys,


I really need help with this one!

I need to be able to delete some entries in the Registry from VBA, and
deleting values and keys with no sub-keys works fine, but problems occurs
when a key have subkeys.

I'm using 'WShell.RegDelete RegistryKey' to delete the entries, no matter if
it is a value or a key, but, as you all probably know, you cannot delete a
key, if it has subkeys.

So, I'm trying to use 'RegObject.ENumKey HKEY, DeleteKey, SubKeys' to get
the number of subkeys to be able to delete those first...

....and it works...

....provided that those subkeys doesn't have any subkeys themselves!

So, to solve this problem, I'm trying to create an UDF to do the work
instead, so I can just call this UDF, like:

DelRegKeyVal(Key) ('Key' can also be a value)

....which should then delete the 'Key' no matter if it is a value or key.

But, since I don't know how many levels down, the key has subkey (if the
name of the argument is an actually key), how do I make sure all sub-, sub-,
sub- keys are deleted before getting up to the level of 'Key'?


Does all this make sense?
Does anyone undderstand my problem, and can help?


Thanks,

CE
 
W

witek

Charlotte said:
Hi Guys,


I really need help with this one!

I need to be able to delete some entries in the Registry from VBA, and
deleting values and keys with no sub-keys works fine, but problems occurs
when a key have subkeys.

I'm using 'WShell.RegDelete RegistryKey' to delete the entries, no matter if
it is a value or a key, but, as you all probably know, you cannot delete a
key, if it has subkeys.

So, I'm trying to use 'RegObject.ENumKey HKEY, DeleteKey, SubKeys' to get
the number of subkeys to be able to delete those first...

...and it works...

...provided that those subkeys doesn't have any subkeys themselves!

So, to solve this problem, I'm trying to create an UDF to do the work
instead, so I can just call this UDF, like:

DelRegKeyVal(Key) ('Key' can also be a value)

...which should then delete the 'Key' no matter if it is a value or key.

But, since I don't know how many levels down, the key has subkey (if the
name of the argument is an actually key), how do I make sure all sub-, sub-,
sub- keys are deleted before getting up to the level of 'Key'?


Does all this make sense?
Does anyone undderstand my problem, and can help?


Thanks,

CE

have you hard word recursion ?

n! = n*(n-1)!

exit if not subkey exits delete key.
call itself with each subkey as parameter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top