delete windows registry section

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!!
LVL 4
broadbentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
Under WindowsNT I think you have to check to make sure the key doesn't have any subitems.
0
VbmasterCommented:
subitems = subkeys
0
VbmasterCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

rovermCommented:
Why don't u use API calls ?
0
broadbentAuthor Commented:
Thanks.
However deleting a section does delete all the values as well.
0
VbmasterCommented:
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
rovermCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.