473,378 Members | 1,623 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,378 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 2731
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.