Cry about...
Delphi Programming with TWebBrowser

How to programmatically clear IE's (and TWebBrowser's) browser history

TWebBrowser and Internet Explorer share the same browser history. The following code defines a unit with the function "ClearInternetExplorerHistory" which will clear IE's browser history.

unit InternetExplorerHistory;


  Windows, ComObj, ActiveX;

procedure ClearInternetExplorerHistory;

  CLSID_CUrlHistory: TGUID = '{3C374A40-BAE4-11CF-BF7D-00AA006946EE}';

  TSTATURL = record
    cbSize: DWORD;
    pwcsUrl: DWORD;
    pwcsTitle: DWORD;
    ftLastVisited: FILETIME;
    ftLastUpdated: FILETIME;
    ftExpires: FILETIME;
    dwFlags: DWORD;

  IEnumSTATURL = interface(IUnknown)
    function Next(celt: Integer; out elt; pceltFetched:
PLongint): HRESULT; stdcall;
    function Skip(celt: Longint): HRESULT; stdcall;
    function Reset: HResult; stdcall;
    function Clone(out ppenum: IEnumSTATURL): HResult; stdcall;
    function SetFilter(poszFilter: PWideChar; dwFlags: DWORD): HResult; stdcall;

  IUrlHistoryStg = interface(IUnknown)
    function AddUrl(pocsUrl: PWideChar; pocsTitle: PWideChar; dwFlags: Integer): HResult; stdcall;
    function DeleteUrl(pocsUrl: PWideChar; dwFlags: Integer): HResult; stdcall;
    function QueryUrl(pocsUrl: PWideChar; dwFlags: Integer; var lpSTATURL: TSTATURL): HResult; stdcall;
    function BindToObject(pocsUrl: PWideChar; var riid: TIID; out ppvOut: Pointer): HResult; stdcall;
    function EnumUrls(out ppenum: IEnumSTATURL): HResult; stdcall;

  IUrlHistoryStg2 = interface(IUrlHistoryStg)
    function AddUrlAndNotify(pocsUrl: PWideChar; pocsTitle: PWideChar; dwFlags: Integer;
fWriteHistory: Integer; var poctNotify: Pointer;
    const punkISFolder: IUnknown): HResult; stdcall;
    function ClearHistory: HResult; stdcall;


procedure ClearInternetExplorerHistory;
  stg: IUrlHistoryStg2;
  stg := CreateComObject(CLSID_CUrlHistory) as IUrlHistoryStg2;


Then to clear the browser history simply call the "ClearInternetExplorerHistory" procedure.

Sadly I cannot take credit for this code - but no longer have a reference to where I obtained it from. If someone can provide me with the original source I will gladly add a suitable acknowledgement.

These notes are believed to be correct for Delphi 6 and 7, but may apply to other versions as well.

About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.