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.
Terms of Agreement:
By using this code, you agree to the following terms...
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.
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.
You may link to this code from another website, but ONLY if it is not wrapped in a frame.
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
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
'This adds an event handler for the button when it is clicked
AddHandler Button1.Click, AddressOf Button1_Click
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)
'Toggle the enable state of the control if it has already been invoked
If Control.Enabled = True Then
Control.Enabled = False
Control.Enabled = True
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
'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
'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
'Windows seems to have a built in feature that is made to prevent you from hiding the window
'So we constantly hide the window over and over
'get the window's handle
Dim hwnd As Integer = Process.MainWindowHandle.ToInt32
'Hide the window
'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
'Inform the user that the internet history has been cleared.
MsgBox("Internet History Has Been Cleared.")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Call the clearinternethistory function
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.)