For some reason the code I have I cannot seem to delete the registry key.
I'm using the basRegistry module, that I grabbed from...Kenneth Ives
I'm calling this piece of code in particular:
Here is my code calling it: (SelectedItem is equal to: HID\VID_0925&PID_8866&COL01\7&21F7DE89&0&0000 for an example)Code:Public Function regDelete_Sub_Key(ByVal lngRootKey As Long, _ ByVal strRegKeyPath As String, _ ByVal strRegSubKey As String) ' -------------------------------------------------------------- ' Written by Kenneth Ives [email protected] ' ' Important: If you treat all key data strings as being ' case sensitive, you should never have a problem. ' Always backup your registry files (System.dat ' and User.dat) before performing any type of ' modifications ' ' Description: Function for removing a sub key. ' ' Parameters: ' lngRootKey - HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, ' HKEY_lOCAL_MACHINE, HKEY_USERS, etc ' strRegKeyPath - is name of the key path you wish to traverse. ' strRegSubKey - is the name of the key which will be removed. ' ' Syntax: ' regDelete_Sub_Key HKEY_CURRENT_USER, _ "Software\AAA-Registry Test\Products", "StringTestData" ' ' Removes the sub key "StringTestData" ' -------------------------------------------------------------- ' -------------------------------------------------------------- ' Define variables ' -------------------------------------------------------------- Dim lngKeyHandle As Long ' -------------------------------------------------------------- ' Make sure the key exist before trying to delete it ' -------------------------------------------------------------- If regDoes_Key_Exist(lngRootKey, strRegKeyPath) Then ' Get the key handle m_lngRetVal = RegOpenKey(lngRootKey, strRegKeyPath, lngKeyHandle) ' Delete the sub key. If it does not exist, then ignore it. m_lngRetVal = RegDeleteValue(lngKeyHandle, strRegSubKey) ' Always close the handle in the registry. We do not want to ' corrupt the registry. m_lngRetVal = RegCloseKey(lngKeyHandle) End If End Function
It doesn't delete the key and no error is returned. Any ideas?Code:Private Sub DelSelectedDev_Click() Dim n As Integer Dim pos1 As Integer Dim pos2 As Integer Dim lngRootKey As Long Dim tempKeyPath1 As String Dim tempKeyPath2 As String Dim tempSubKeyName1 As String Dim tempSubKeyName2 As String pos1 = InStr(selectedItem, "\") pos2 = InStr(pos1 + 1, selectedItem, "\") lngRootKey = HKEY_LOCAL_MACHINE MsgBox pos2 On Error GoTo errorhandler If pos2 = 0 Then MsgBox "Invalid Key Name, unable to delete!" End Else tempKeyPath1 = "SYSTEM\CurrentControlSet\Enum\" & selectedItem tempKeyPath2 = Left(selectedItem, pos2) tempSubKeyName1 = "Device Parameters" tempSubKeyName2 = "Log Conf" tempSubKeyName3 = Right(tempKeyPath1, (Len(selectedItem) - pos2)) MsgBox tempKeyPath1 MsgBox tempKeyPath2 MsgBox tempSubKeyName1 MsgBox tempSubKeyName2 MsgBox tempSubKeyName3 regDelete_Sub_Key lngRootKey, tempKeyPath1, tempSubKeyName1 regDelete_Sub_Key lngRootKey, tempKeyPath1, tempSubKeyName2 regDelete_Sub_Key lngRootKey, tempKeyPath2, tempSubKeyName3 End If errorhandler: MsgBox Err.Number & ": " & Err.Description




Reply With Quote