Public Class fClearHist
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents bExit As System.Windows.Forms.Button
Friend WithEvents bClear As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.bClear = New System.Windows.Forms.Button
Me.bExit = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'bClear
'
Me.bClear.Location = New System.Drawing.Point(8, 8)
Me.bClear.Name = "bClear"
Me.bClear.Size = New System.Drawing.Size(64, 24)
Me.bClear.TabIndex = 0
Me.bClear.Text = "Clear"
'
'bExit
'
Me.bExit.Location = New System.Drawing.Point(136, 8)
Me.bExit.Name = "bExit"
Me.bExit.Size = New System.Drawing.Size(64, 24)
Me.bExit.TabIndex = 1
Me.bExit.Text = "Exit"
'
'fClearHist
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(210, 46)
Me.Controls.Add(Me.bExit)
Me.Controls.Add(Me.bClear)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Name = "fClearHist"
Me.Text = "Clear IE History"
Me.ResumeLayout(False)
End Sub
#End Region
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
(ByVal hKey As Long, ByVal lpSubKey As String) As Long
' Delete a registry key
'
' Under Windows NT it doesn't work if the key contains subkeys
Sub DeleteRegistryKey(ByVal hKey As Long, ByVal KeyName As String)
RegDeleteKey(hKey, KeyName)
End Sub
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, ByVal phkResult As Long) As Long
Const KEY_READ = &H20019 ' ((READ_CONTROL Or KEY_QUERY_VALUE Or
' KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not
' SYNCHRONIZE))
' Return True if a Registry key exists
Function CheckRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As _
Boolean
Dim handle As Long
' Try to open the key
If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) = 0 Then
' The key exists
CheckRegistryKey = True
' Close it before exiting
RegCloseKey(handle)
End If
End Function
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
"RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal Reserved As Long, ByVal lpClass As Long, ByVal dwOptions As Long, _
ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, _
ByVal phkResult As Long, ByVal lpdwDisposition As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As _
Long
' KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not
' SYNCHRONIZE))
Const REG_OPENED_EXISTING_KEY = &H2
' Create a registry key, then close it
' Returns True if the key already existed, False if it was created
Function CreateRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As _
Boolean
Dim handle As Long, disposition As Long
If RegCreateKeyEx(hKey, KeyName, 0, 0, 0, 0, 0, handle, disposition) Then
Err.Raise(1001, , "Unable to create the registry key"

Else
' Return True if the key already existed.
CreateRegistryKey = (disposition = REG_OPENED_EXISTING_KEY)
' Close the key.
RegCloseKey(handle)
End If
End Function
Public Sub ClearIEHistory()
Const HKEY_CURRENT_USER = &H80000001
Dim sKey As String
sKey = "Software\Microsoft\Internet Explorer\TypedURLs"
' delete the key that contains the URLs the history
DeleteRegistryKey(HKEY_CURRENT_USER, sKey)
' recreate the key, empty
CreateRegistryKey(HKEY_CURRENT_USER, sKey)
End Sub
Private Sub bClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bClear.Click
ClearIEHistory()
End Sub
End Class