Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy way to clear IE History

Status
Not open for further replies.

rborel

MIS
Dec 3, 2002
29
US
Does anyone have an easy way to clear IE history? I've tried deleting the folders under the History folder but they seem to be "special". I did run across one article that mentioned deleting reg keys but I couldn't seem to get the code to work (not sure if it was VB6 or .NET) in .NET.

Thanks for any suggestions or directions.

R.
 
This code should do the trick for you.

Not mine. It is from VB To the max




DotNetDoc
M.C.S.D.
[2thumbsup]
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Thanks for the reply but, I found that article and was unable to get it to work. It failed on the "deleteregistrykey". I'll try it again and post the error.

Thanks again for the reply.
 
You need to implement both functions on the bottom of that article. deletregistrykey is one of them. Did you do this as well. If so let me know and I will look at the code again. It had worked for me in the past


DotNetDoc
M.C.S.D.
[2thumbsup]
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
This is what I get;

An unhandled exception of type 'System.NullReferenceException' occurred in ClearIEHist.exe

Additional information: Object reference not set to an instance of an object.

When I first copy/paste into VB.NET I get;
C:\My Documents\Visual Studio Projects\ClearIEHist\fClearHist.vb(111): 'KEY_READ' is already declared as 'Private Const KEY_READ = 131097' in this class.

And;

C:\My Documents\Visual Studio Projects\ClearIEHist\fClearHist.vb(83): Method 'RegCloseKey' has multiple definitions with identical signatures.

And;

C:\My Documents\Visual Studio Projects\ClearIEHist\Get_User_Function.vb(15): Method 'RegOpenKeyEx' has multiple definitions with identical signatures.

Build errors. But when I comment them out to get rid of the errors I get the unhandled exception error.


If I haven't mentioned it. Thanks for all the suggestions/ideas it really is appreciated.
 
The first error is saying that you are trying to use and object without instantiating it. The others are because the functions are already declared.

Paste all your code in here so I can see what you are doing.

DotNetDoc
M.C.S.D.
[2thumbsup]
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
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 = &quot;bClear&quot;
Me.bClear.Size = New System.Drawing.Size(64, 24)
Me.bClear.TabIndex = 0
Me.bClear.Text = &quot;Clear&quot;
'
'bExit
'
Me.bExit.Location = New System.Drawing.Point(136, 8)
Me.bExit.Name = &quot;bExit&quot;
Me.bExit.Size = New System.Drawing.Size(64, 24)
Me.bExit.TabIndex = 1
Me.bExit.Text = &quot;Exit&quot;
'
'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 = &quot;fClearHist&quot;
Me.Text = &quot;Clear IE History&quot;
Me.ResumeLayout(False)

End Sub

#End Region

Private Declare Function RegDeleteKey Lib &quot;advapi32.dll&quot; Alias &quot;RegDeleteKeyA&quot; _
(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 &quot;advapi32.dll&quot; Alias &quot;RegOpenKeyExA&quot; _
(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 &quot;advapi32.dll&quot; Alias _
&quot;RegCreateKeyExA&quot; (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 &quot;advapi32.dll&quot; (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, , &quot;Unable to create the registry key&quot;)
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 = &quot;Software\Microsoft\Internet Explorer\TypedURLs&quot;
' 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top