Important alert: (current site time 5/21/2013 12:33:08 PM EDT)
 

VB icon

Clear Internet Explorer History, Hidden Window

Email
Submitted on: 9/26/2012 9:49:34 AM
By: Paul Ishak 
Level: Intermediate
User Rating: Unrated
Compatibility: VB.NET
Views: 1323
author picture
(About the author)
 
     A question was asked the other day: "How do I clear internet history from vb, without showing the window?". Here is how I would do it, I thought I would share the answer here, instead of where the question was asked.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Clear Internet Explorer History, Hidden Window
// Description:A question was asked the other day: "How do I clear internet history from vb, without showing the window?". Here is how I would do it, I thought I would share the answer here, instead of where the question was asked.
// By: Paul Ishak
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=8858&lngWId=10//for details.//**************************************

Option Strict On
Imports System.Threading
Public Class Form1
'Declare Windows Api Function
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal command As Integer) As Integer
'This is used for multi threading, making thread safe calls.
Private Delegate Sub ToggleControlEnableState(ByVal Control As Control)
'Declare a button for the form
Friend WithEvents Button1 As New Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'This is used for centering the button on the form
Dim Padding As Integer = 20
'This is how to calculate the border width of the form
Dim BorderWidth As Integer = Me.Width - Me.ClientRectangle.Width
'This is how to calculate the border height of the form
Dim BorderHeight As Integer = Me.Height - Me.ClientRectangle.Height
'This sets the form width
Me.Width = Button1.Width + (Padding * 2) + BorderWidth
'This sets the form height
Me.Height = Button1.Height + (Padding * 2) + BorderHeight
'This sets the X cooridinate of the button
Button1.Left = (Me.Width \ 2) - (Button1.Width \ 2)
'This sets the Y cooridinate of the button
Button1.Top = (Me.ClientRectangle.Height \ 2) - (Button1.Height \ 2)
'This sets the Text on the button
Button1.Text = "Clear History"
'This adds the button to the form
Me.Controls.Add(Button1)
'This adds an event handler for the button when it is clicked
AddHandler Button1.Click, AddressOf Button1_Click
End Sub
Sub ToggleEnable(ByVal Control As Control)
'This is for safe cross thread calls
'Invoke the control if it has not yet been invoked
If Control.InvokeRequired Then
Control.Invoke(New ToggleControlEnableState(AddressOf ToggleEnable), Control)
Else
'Toggle the enable state of the control if it has already been invoked
If Control.Enabled = True Then
Control.Enabled = False
Else
Control.Enabled = True
End If
End If
End Sub
Public Sub ClearInternetHistory()
'Create a new thread so the UI can remain responsive
Dim Thread As New Thread(AddressOf ThreadWork)
'Start execution of the new thread
Thread.Start()
End Sub
Sub ThreadWork()
'This sub is the code that will be executed from the multi thread
'Make thread safe call to change the enable state of the button
ToggleEnable(Button1)
'Create a new process to launch the internet browsing history deleter
Dim Process As New Process
'Set the file name
Process.StartInfo.FileName = "RunDll32.exe"
'Set the command line arguments
Process.StartInfo.Arguments = "InetCpl.cpl,ClearMyTracksByProcess 255"
'Start the process
Process.Start()
'Windows seems to have a built in feature that is made to prevent you from hiding the window
Do
'So we constantly hide the window over and over
'get the window's handle
Dim hwnd As Integer = Process.MainWindowHandle.ToInt32
'Hide the window
ShowWindow(hwnd, 0)
'Until the window is done doing its work
Loop Until Process.HasExited
'We are done now, so me make a safe cross thread call to re-enable the button
ToggleEnable(Button1)
'Inform the user that the internet history has been cleared.
MsgBox("Internet History Has Been Cleared.")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Call the clearinternethistory function
ClearInternetHistory()
End Sub
End Class


Other 17 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.