Solved

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

Posted on 2006-11-28
5
1,185 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 125 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

730 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