How to delete registry keys with subkeys???

Posted on 2001-07-30
Last Modified: 2007-12-19
The RegDeleteKey API only works for keys that do not have subkeys.  How do I delete the entire branch even though it has subkeys beneath it???  Anyone?

Question by:msejfovic

Expert Comment

ID: 6335722

Author Comment

ID: 6335731
I meant through an API call

Accepted Solution

DennisBorg earned 5 total points
ID: 6335861
>The RegDeleteKey API only works for keys that do not have subkeys.

This is true for WinNT and Win2K. If you have Win95/ Win98, then it also deletes all subkeys.

For WinNT and Win2K, you'll want to use the SHDeleteKey Win API function, from Version 4.71 and later of Shlwapi.dll

I haven't been able to find the declaration for it to use in VB, but I imagine it is one of the following:

Public Declare Function SHDeleteKey Lib "shlwapi.dll" Alias "SHDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long


Public Declare Function SHDeleteKey Lib "shlwapi.dll" (ByVal hKey As Long, ByVal lpSubKey As String) As Long

Perhaps someone else can confirm the declaration statement for this function.

-Dennis Borg
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

LVL 43

Expert Comment

ID: 6336097
Dennis I believe it should be Public Declare Function SHDeleteKey Lib "shlwapi.dll" Alias "SHDeleteKeyA" (ByVal hKey As Long, ByVal
lpSubKey As String) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002

Used as
Dim Return As Long
Return = SHDeleteKey (HKEY_LOCAL_MACHINE,"\Software\Microsoft\Etc\Etc" & Chr(0))

I have not used it myself but give it a try.

LVL 49

Expert Comment

ID: 7161675
Hi msejfovic,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept DennisBorg@idg's comment(s) as an answer.

msejfovic, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7182446
Comment from expert accepted as answer

E-E Moderator

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now