[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Delete only some value from "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs"

Posted on 2006-11-28
5
Medium Priority
?
1,207 Views
Last Modified: 2008-01-16
We all know that web addresses are stored in registry, key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs. It's simply to have IE delete all of them or delete them manually by using registry.

The problem is: How to use VB6 to delete only some value from "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs", for example: there are a lot of web addressses typed urls in registry, and I want to get them all listed in a VB combobox (or VB listbox) in order to see and delete them selectively as I expected.

I haved tried the code at: http://www.arcatapet.net/vbregget.cfm and http://www.arcatapet.net/vbregset.cfm but they are only useful if I know clearly the address and only get one address at a time, the problem still: I want to get them all listed in a VB combobox (or VB listbox) in order to see all and delete them selectively as I expected (VB6).

NOTE: from Microsoft: Values in this registry key are listed as Url1, Url2, Url3, and so on. If you delete only some values and the remaining values are not in consecutive numerical order, only some of the remaining entries are listed in the Address box. To prevent this behavior from occurring, rename the remaining values so that they are in consecutive numerical order.
0
Comment
Question by:taycuong76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 18029702
If you are going to do this the basic breakdown you will need to both read and delete the values using API are below:
You should add them to an array so you can easily reference which values your deleting.

1. To open the handle to the key you could shoot for one of the API's below:

RegOpenCurrentUser, RegOpenKey

2. To enumerate the value name in the TypedUrls key you should use:
RegEnumValue

3. To Query the actual value data you should use
RegQueryValue,RegQueryValueEx

4. To delete the value use:
RegDeleteValue
0
 
LVL 28

Accepted Solution

by:
Ark earned 500 total points
ID: 18033143
Add listbox (style=checkbox) and command button on form

Option Explicit

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData 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 ERROR_SUCCESS = 0&
Private Const HKEY_CURRENT_USER = &H80000001
Private Const KEY_ALL_ACCESS = &HF003F
Private Const REG_SZ = 1

Private Function EnumTypedURLs() As Variant
   Dim sURLs() As String
   Dim sName As String, sValue As String
   Dim abData() As Byte
   Dim hKey As Long, i As Long, count As Long
   Dim name_length As Long, value_length As Long
   If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\TypedURLs", 0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS Then
      MsgBox "Error opening key."
      Exit Function
   End If
   ReDim sURLs(0)
   Do
      name_length = 1024
      value_length = 1024
      sName = Space(name_length)
      ReDim abData(value_length)
      If RegEnumValue(hKey, i, sName, name_length, 0, REG_SZ, abData(0), value_length) <> ERROR_SUCCESS Then Exit Do
      sName = Left(sName, name_length)
      sValue = Left(StrConv(abData, vbUnicode), value_length)
      ReDim Preserve sURLs(i)
      sURLs(i) = sName & "=" & sValue
      i = i + 1
   Loop
   RegCloseKey hKey
   EnumTypedURLs = sURLs
End Function

Private Sub Command1_Click()
   Dim i As Long
   For i = 0 To List1.ListCount - 1
       If List1.Selected(i) Then
          DeleteTypedURLs List1.List(i)
       End If
   Next
   UpdateListBox
End Sub

Private Sub Form_Load()
   Caption = "Typed URLs"
   Command1.Caption = "Delete"
   UpdateListBox
End Sub

Private Sub DeleteTypedURLs(ByVal sURL As String)
   Dim hKey As Long
   If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\TypedURLs", 0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS Then
      MsgBox "Error opening key."
      Exit Sub
   End If
   RegDeleteValue hKey, Split(sURL, "=")(0)
   RegCloseKey hKey
End Sub

Private Sub UpdateListBox()
   Dim vURLs As Variant
   Dim i As Long
   List1.Clear
   vURLs = EnumTypedURLs
   If IsEmpty(vURLs) Then Exit Sub
   For i = 0 To UBound(vURLs)
       List1.AddItem (vURLs(i))
   Next i
End Sub

0
 
LVL 3

Author Comment

by:taycuong76
ID: 18033792
Wow! thanks Ark, your code worked like a champ ! You surely got the point.
If you don't mind, please help me to set the remaining values (after deleting some values) so that they are in consecutive numerical order.
Microsoft say that: Values in this registry key are listed as Url1, Url2, Url3, and so on. If you delete only some values and the remaining values are not in consecutive numerical order, only some of the remaining entries are listed in the Address box, the rests are useless.
Regards.
Tran Hoai Nam
0
 
LVL 28

Expert Comment

by:Ark
ID: 18034094
Option Explicit

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) 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 Const ERROR_SUCCESS = 0&
Private Const HKEY_CURRENT_USER = &H80000001
Private Const KEY_ALL_ACCESS = &HF003F
Private Const REG_SZ = 1

Private Function EnumTypedURLs() As Variant
   Dim sURLs() As String
   Dim sName As String, sValue As String
   Dim abData() As Byte
   Dim hKey As Long, i As Long, count As Long
   Dim name_length As Long, value_length As Long
   If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\TypedURLs", 0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS Then
      MsgBox "Error opening key."
      Exit Function
   End If
   ReDim sURLs(0)
   Do
      name_length = 1024
      value_length = 1024
      sName = Space(name_length)
      ReDim abData(value_length)
      If RegEnumValue(hKey, i, sName, name_length, 0, REG_SZ, abData(0), value_length) <> ERROR_SUCCESS Then Exit Do
      sName = Left(sName, name_length)
      sValue = Left(StrConv(abData, vbUnicode), value_length)
      ReDim Preserve sURLs(i)
      sURLs(i) = sName & "=" & sValue
      i = i + 1
   Loop
   RegCloseKey hKey
   EnumTypedURLs = sURLs
End Function

Private Sub Command1_Click()
   Dim i As Long, count As Long
   Dim sURL As Variant
   For i = 0 To List1.ListCount - 1
       sURL = Split(List1.List(i), "=")
       DeleteTypedURLs Trim(sURL(0))
       If List1.Selected(i) = False Then
          count = count + 1
          RestoreTypedURLs "url" & count, Trim(sURL(1))
       End If
   Next
   UpdateListBox
End Sub

Private Sub Form_Load()
   Caption = "Typed URLs"
   Command1.Caption = "Delete"
   UpdateListBox
End Sub

Private Sub RestoreTypedURLs(ByVal sName As String, sValue As String)
   Dim hKey As Long
   If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\TypedURLs", 0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS Then
      MsgBox "Error opening key."
      Exit Sub
   End If
   
   If RegSetValueEx(hKey, sName, 0&, REG_SZ, ByVal sValue, Len(sValue)) Then
      MsgBox "Error setting value."
'      Exit Function
   End If
   RegCloseKey hKey
End Sub

Private Sub DeleteTypedURLs(ByVal sName As String)
   Dim hKey As Long
   If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\TypedURLs", 0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS Then
      MsgBox "Error opening key."
      Exit Sub
   End If
   RegDeleteValue hKey, sName
   RegCloseKey hKey
End Sub

Private Sub UpdateListBox()
   Dim vURLs As Variant
   Dim i As Long
   List1.Clear
   vURLs = EnumTypedURLs
   If IsEmpty(vURLs) Then Exit Sub
   For i = 0 To UBound(vURLs)
       List1.AddItem (vURLs(i))
   Next i
End Sub

0
 
LVL 3

Author Comment

by:taycuong76
ID: 18034129
Great! thanks and best wishes.
Regard.
Tran Hoai Nam
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question