?
Solved

delete windows registry section

Posted on 2000-01-26
7
Medium Priority
?
178 Views
Last Modified: 2010-05-18
this code deletes a Windows Registry setting and works fine under Windows 98

Public Function DeleteSetting(ByVal Section As String, Optional ByVal Key As String = "") As Boolean
Dim hKey&, r&
Section = m_AppName & omBSlash & Section
If Key = "" Then
  r = RegDeleteKey(m_hClassKey, Section)
  If r Then DeleteSetting = False Else DeleteSetting = (r = ERROR_SUCCESS)
Else
  r = RegOpenKeyEx(m_hClassKey, Section, 0&, KEY_ALL_ACCESS, hKey)
  If r Then
      DeleteSetting = False
  Else
    r = RegDeleteValue(hKey, Key)
    If r Then DeleteSetting = False Else DeleteSetting = (r = ERROR_SUCCESS)
  End If
End If
End Function

but doesn't under Windows NT

this line fails:-
  r = RegDeleteKey(m_hClassKey, Section)

under Windows98, if the section exists then r=0 else r=2
and it works

under WindowsNT, if the section exists then r=5 else r=2
and it fails to delete the section

Help please!!
0
Comment
Question by:broadbent
  • 4
  • 2
7 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2388288
Under WindowsNT I think you have to check to make sure the key doesn't have any subitems.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2388290
subitems = subkeys
0
 
LVL 7

Accepted Solution

by:
Vbmaster earned 300 total points
ID: 2388295
Found the info I had read before about RegDeleteKey and NT..

"RegDeleteKey deletes a key from the registry. The key to delete cannot have any subkeys under it or else the delete operation will fail. Under Win NT, the function will also fail if there are any values still under the key to delete. However, under Win 95/98, the function will still work; the key and all its associated values will be deleted. The function returns 0 if successful, or a non-zero error code if an error occured. "

http://www.vbapi.com/ref/r/regdeletekey.html

I guess you will have to make a recursive deletion process to delete all the subkeys and subitems before deleting the item. No biggie but hell NT makes programming a pain in the **** sometimes. ;)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 12

Expert Comment

by:roverm
ID: 2388504
Why don't u use API calls ?
0
 
LVL 4

Author Comment

by:broadbent
ID: 2388681
Thanks.
However deleting a section does delete all the values as well.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2388735
roverm: take a look at the code, and you'll see what was discussed here WAS api calls but sometimes NT screws it up.. or however you want to see it ('features' anyone?).
0
 
LVL 12

Expert Comment

by:roverm
ID: 2388813
Sorry. Didn't understand you tried it already !
But: According to the MSDN OnLine:
Use the SHDeleteKey API to delete subkeys and all of its descendants.
First enum them, but ok, it should work?
Tried that also ?
grtx, RoverM
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

588 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