473,287 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Problem deleting registery values with its subkeys

6
I am trying to delete registery key encluding all its subkeys . I want to delete the bold part

HKEY_CURRENT_USER, "Software\xyz\foldername\"

using an api that i found on the net but i keep geting error!! could any one tell me how to delete entire key with its subkeys ?


I changed :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command3_Click()
  2.     'Delete the setting from the registry
  3.     DelSetting HKEY_CURRENT_USER, "KPD-Team", "BinaryValue"
  4.     MsgBox "The value was deleted ...", vbInformation + vbOKOnly, App.Title
  5. End Sub


to





Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2.     'Delete the setting from the registry
  3.     DelSetting HKEY_CURRENT_USER, "Software\xyz\foldername\"
  4.     MsgBox "The value was deleted ...", vbInformation + vbOKOnly, App.Title
  5.  
  6. End Sub



But it did not work and give me that error!!!!


error:


Expand|Select|Wrap|Line Numbers
  1. Compile error:
  2.  
  3. Argument not optional 
and pointing at :

DelSetting



Orginal API code


Expand|Select|Wrap|Line Numbers
  1. 'This program needs 3 buttons
  2. Const REG_SZ = 1 ' Unicode nul terminated string
  3. Const REG_BINARY = 3 ' Free form binary
  4. Const HKEY_CURRENT_USER = &H80000001
  5. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  6. Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  7. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
  8. Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  9. 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
  10. 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
  11. Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
  12.     Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
  13.     'retrieve nformation about the key
  14.     lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
  15.     If lResult = 0 Then
  16.         If lValueType = REG_SZ Then
  17.             'Create a buffer
  18.             strBuf = String(lDataBufSize, Chr$(0))
  19.             'retrieve the key's content
  20.             lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
  21.             If lResult = 0 Then
  22.                 'Remove the unnecessary chr$(0)'s
  23.                 RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
  24.             End If
  25.         ElseIf lValueType = REG_BINARY Then
  26.             Dim strData As Integer
  27.             'retrieve the key's value
  28.             lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
  29.             If lResult = 0 Then
  30.                 RegQueryStringValue = strData
  31.             End If
  32.         End If
  33.     End If
  34. End Function
  35. Function GetString(hKey As Long, strPath As String, strValue As String)
  36.     Dim Ret
  37.     'Open the key
  38.     RegOpenKey hKey, strPath, Ret
  39.     'Get the key's content
  40.     GetString = RegQueryStringValue(Ret, strValue)
  41.     'Close the key
  42.     RegCloseKey Ret
  43. End Function
  44. Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
  45.     Dim Ret
  46.     'Create a new key
  47.     RegCreateKey hKey, strPath, Ret
  48.     'Save a string to the key
  49.     RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
  50.     'close the key
  51.     RegCloseKey Ret
  52. End Sub
  53. Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
  54.     Dim Ret
  55.     'Create a new key
  56.     RegCreateKey hKey, strPath, Ret
  57.     'Set the key's value
  58.     RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
  59.     'close the key
  60.     RegCloseKey Ret
  61. End Sub
  62. Sub DelSetting(hKey As Long, strPath As String, strValue As String)
  63.     Dim Ret
  64.     'Create a new key
  65.     RegCreateKey hKey, strPath, Ret
  66.     'Delete the key's value
  67.     RegDeleteValue Ret, strValue
  68.     'close the key
  69.     RegCloseKey Ret
  70. End Sub
  71. Private Sub Command1_Click()
  72.     Dim strString As String
  73.     'Ask for a value
  74.     strString = InputBox("Please enter a value between 0 and 255 to be saved as a binary value in the registry.", App.Title)
  75.     If strString = "" Or Val(strString) > 255 Or Val(strString) < 0 Then
  76.         MsgBox "Invalid value entered ...", vbExclamation + vbOKOnly, App.Title
  77.         Exit Sub
  78.     End If
  79.     'Save the value to the registry
  80.     SaveStringLong HKEY_CURRENT_USER, "KPD-Team", "BinaryValue", CByte(strString)
  81. End Sub
  82. Private Sub Command2_Click()
  83.     'Get a string from the registry
  84.     Ret = GetString(HKEY_CURRENT_USER, "KPD-Team", "BinaryValue")
  85.     If Ret = "" Then MsgBox "No value found !", vbExclamation + vbOKOnly, App.Title: Exit Sub
  86.     MsgBox "The value is " + Ret, vbOKOnly + vbInformation, App.Title
  87. End Sub
  88. Private Sub Command3_Click()
  89.     'Delete the setting from the registry
  90.     DelSetting HKEY_CURRENT_USER, "KPD-Team", "BinaryValue"
  91.     MsgBox "The value was deleted ...", vbInformation + vbOKOnly, App.Title
  92. End Sub
  93. Private Sub Form_Load()
  94.     'KPD-Team 1998
  95.     'URL: http://www.allapi.net/
  96.     'E-Mail: KPDTeam@Allapi.net
  97.     Command1.Caption = "Set Value"
  98.     Command2.Caption = "Get Value"
  99.     Command3.Caption = "Delete Value"
  100. End Sub
Jun 17 '06 #1
1 2728
BSOB
77
this string might be a bit stale and you might have forgotten about it. but...
the DelSetting function required 3 arguements as in the example. you are only giving it two. you think it should make sence, and to a human, sure. what i would do is first explore that registry key and create a list of all the subkeys, store that list in a variable array. then, delete each subkey in that list seperately.
Jul 15 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: James | last post by:
Help! I've made a cookie with a key called 'List' and subkey 'item3' and assigned it a value of "3" Response.Cookies("List")("item3")="3" How do I now delete the subkey "item3" without...
7
by: Brian Henry | last post by:
I am trying to deploy my VB.NET project with a setup project, and I need to make a reg key entry.. but it also needs to have the path to where the program was installed in they string i placed in...
1
by: method | last post by:
Hi all i am usiing this code to write mulitiple values to registery but it only write one value. could any one help me make this code so that it write multiple values to registery. Currently it only...
0
by: aboxylica | last post by:
i have a code which calculates a set of log values when two inputs are given..a set of sequence files and a set of matrix files. now what i should be doing is that my i/p sequence is a folder...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.