Link to home
Start Free TrialLog in
Avatar of 471094
471094

asked on

How to delete a subkey from the registry in VB6

Hello.

I am just starting to get involved in working with the system registry and I have stumbled on a hang up.  I cant figure out how to delete a selected subkey in the registry from a listbox.  For example I need to be able to click on a subkey in a list box and delete it from the registry.  The following is a subkey I want to delete:  

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\ehTray.exe

Avatar of 471094
471094

ASKER

Update---  I just need to be able to delete the ehTray.exe subkey.  Sorry.
ASKER CERTIFIED SOLUTION
Avatar of Don
Don
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you need more help with the registry in the future so experts do not get confused. You can refer to them as Value Name and Value Data. A subkey is confusing because experts looking at your question might think you mean an actual subkey. In this particular question you did give an example which indicates you want to remove a Value Name from the registry but without that example many would assume you need to delete a subkey. :)

try sumthing like this....

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005


sComputer = "MyComputer"
sMethod = "DeleteKey"
hTree = HKEY_CURRENT_USER
sKey = "Software\Microsoft\Windows\CurrentVersion\Run\ehTray.exe"


Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
        sComputer & "/root/default:StdRegProv")

Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()

oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey

Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)




'''''''''''''''''''''
or visit this link for more information....

http://www.serverwatch.com/tutorials/article.php/1476861


game-master