|
-
Aug 1st, 2000, 05:38 AM
#1
Thread Starter
Hyperactive Member
Hey guys thanks for the code but I forgot to ask how to delete from the registry. Seems simple but its not working. I pass the values to the function and I don't get an error but it still does not delete the string from the registry. Code below EzTelnet is Entry I need to delete module code is below that THANKS ALL!!!!
'Delete the Registry Entry Not working yet
DelRegSetting HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run\EzTelnet"
'MODULE
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_DYN_DATA = &H80000006
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_USERS = &H80000003
Public Sub SaveRegSetting(ByVal lKey As Long, ByVal sSubKey As String, ByVal sValue As String, ByVal vData As Variant)
'Save a String/Long Value to the Registry
Dim lRegKey As Long
Dim lType As Long
Dim lData As Long
Dim sData As String
'Determine the type of Data being Saved
lType = IIf(VarType(vData) = vbString, 1, 4)
If lType = 4 Then
'Long Data Type
lData = vData
Else
'String Data Type
sData = vData
End If
If RegCreateKey(lKey, sSubKey, lRegKey) = 0 Then
'Open/Create the Registry Key
If lType = 1 Then
'Save the String Value to the Registry
Call RegSetValueEx(lRegKey, sValue, 0&, lType, ByVal sData, Len(sData))
Else
'Save the Long Value to the Registry
Call RegSetValueEx(lRegKey, sValue, 0&, lType, lData, 4)
End If
'Close the Registry Key
Call RegCloseKey(lRegKey)
End If
End Sub
Public Function GetRegSetting(ByVal lKey As Long, ByVal sSubKey As String, ByVal sValue As String) As Variant
'Retrieve a String/Long Value from the Registry
Dim lRegKey As Long
Dim lData As Long
Dim sData As String
Dim lType As Long
'Open the Registry Key
If RegOpenKey(lKey, sSubKey, lRegKey) = 0 Then
'Find out the Data Type of the Value to Retrieve
Call RegQueryValueEx(lRegKey, sValue, 0&, lType, ByVal 0&, 0&)
sData = Space(255)
If lType = 1 Then
'Return a String Value
Call RegQueryValueEx(lRegKey, sValue, 0&, lType, ByVal sData, Len(sData))
If InStr(sData, Chr(0)) Then
sData = Left$(sData, InStr(sData, Chr(0)) - 1)
End If
Else
'Return a Long Value
Call RegQueryValueEx(lRegKey, sValue, 0&, lType, lData, 4)
End If
GetRegSetting = IIf(lType = 1, sData, lData)
'Close the Registry Key
Call RegCloseKey(lRegKey)
End If
End Function
Public Sub DelRegSetting(ByVal lKey As Long, ByVal sSubKey As String)
Call RegDeleteKey(lKey, sSubKey)
End Sub
-
Aug 1st, 2000, 05:47 AM
#2
Fanatic Member
Well i'm not one of the guru's, but...
[CODE]
Call RegDeleteKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run\EzTelnet")
Laterz,
D!m
PS. http://www.freevbcode.com/ShowCode.Asp?ID=314 it's a pretty good example of registry functions.
[Edited by Dim on 08-01-2000 at 07:07 AM]
-
Aug 1st, 2000, 11:49 AM
#3
Thread Starter
Hyperactive Member
Doesn't work I tried that??? Anyone else care to try
-
Aug 1st, 2000, 12:47 PM
#4
This shold work:
Code:
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Private Const ERROR_SUCCESS = 0
Private Const HKEY_LOCAL_MACHINE = &H80000002
Public Function DeleteKey(pKey As String, pSubKey As String, pHive As Long)
Dim lngKey As Long
Dim strKey As String
Dim lngRet As Long
lngRet = RegOpenKey(HKEY_LOCAL_MACHINE, pKey, lngKey)
If lngRet = ERROR_SUCCESS Then
lngRet = RegDeleteKey(lngKey, pSubKey)
If lngRet <> ERROR_SUCCESS Then
MsgBox "Error Deleting SubKey.", vbInformation, "Error"
End If
End If
End Function
Then you can use this function like this:
Code:
Private Sub Command1_Click()
DeleteKey "SOFTWARE", "MyProgram", HKEY_LOCAL_MACHINE
End Sub
-
Aug 1st, 2000, 01:39 PM
#5
Thread Starter
Hyperactive Member
Serg I get an error on delete registry entry
Here is what I am using. When I step through the code it seems to be working but I get an error. This is driving me crazy. I have been trying to create this delete functio but I just can't figure it out?? any ideas?
Private Sub Command1_Click()
Dim SOFTWARE As String
Dim MyProgram As String
MyProgram = "EzTelnet" 'This is the String
SOFTWARE = "Software\Microsoft\Windows\CurrentVersion\Run" 'This is where the string resides
DeleteKey SOFTWARE, MyProgram, HKEY_LOCAL_MACHINE
End Sub
-
Aug 1st, 2000, 01:51 PM
#6
Thread Starter
Hyperactive Member
-
Aug 1st, 2000, 02:58 PM
#7
Ohh, I see what you're trying to do. You're trying to delete a value (not a key) from the Run key. In this case you can do something like this:
Code:
Option Explicit
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Private Const ERROR_SUCCESS = 0
Private Const HKEY_LOCAL_MACHINE = &H80000002
Public Function DeleteValue(pKey As String, pValue As String, pHive As Long)
Dim lngKey As Long
Dim strKey As String
Dim lngRet As Long
lngRet = RegOpenKey(HKEY_LOCAL_MACHINE, pKey, lngKey)
If lngRet = ERROR_SUCCESS Then
lngRet = RegDeleteValue(lngKey, pValue)
If lngRet <> ERROR_SUCCESS Then
MsgBox "Error Deleting SubKey.", vbInformation, "Error"
End If
End If
End Function
Then use it similar to DeleteKey:
Code:
Private Sub Command1_Click()
Dim strKey As String
strKey = "Software\Microsoft\Windows\CurrentVersion\Run"
DeleteValue strKey, "EzTelnet", HKEY_LOCAL_MACHINE
End Sub
Regards,
-
Aug 1st, 2000, 03:17 PM
#8
Thread Starter
Hyperactive Member
Serg You are the man!! Thanks that work (of course)
Serg You are the man!! Thanks that work (of course) I always seem to have good luck with the help that you offer thanks again!!
-
Aug 1st, 2000, 03:23 PM
#9
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|