| The Windows Registry: from the Ground UpDeleting Keys
From the Windows Registry
Now how do you delete keys from the registry? This is where the warning comes in, but only to Windows 95/98 users. If you delete a sub-key in the registry, the sub-key and everything below it is deleted. This is where a piece of security comes by first querying if there are any sub-keys below the sub-key that you want to delete. On Windows NT however deletion of keys that contains other sub-keys is not allowed for security reasons. The API function that you need are RegDeleteKey. The RegQueryInfoKey. API function can be used and is shown in the structured class at the end of this article. The RegDeleteKey has the following parameters: hKey This is the registry key that you want to open (see above) lpSubKey This is the sub-key that you want to delete, including all sub-keys below the sub-key that you want to delete. Start a new standard-EXE project, and add a command button to form1. Sets the name to cmdDeleteKey and the caption to Delete Key. Option Explicit Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias _ "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Sub cmdDeleteKey_Click() If RegDeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\MW-SOFTWARE") = 0 Then ' Call the API function and check 0 for ' success MsgBox "The sub-key and all data contained has been deleted", vbInformation Else ' Error MsgBox "Cannot find sub-key", vbCritical End If End Sub This must be the easiest to accomplish registry function and also the most dangerous one if misused. This concludes this section of the article and you now be able to:
|
___________________________________________ Send Bugs, comments to the webmaster at webmaster@mwe.8m.com © 1999 MW Software, all rights reserved |