TIP: IE URL History Tool (Yet Another)

This article will explain the usage of the IE COM object “CUrlHistory”. This COM object allows access to IE’s history. Unfortunately, the MSDN description of this object is far from complete. According to MSDN, access to IE starting from “Internet Explorer 5.5” is obtained through the IUrlHistoryStg or IUrlHistoryStg2 interface. These interfaces are implemented in shdocvw.dll by a COM object with CLSID “CLSID_CUrlHistory”, also defined as “SID_SUrlHistory”.

To get access to IUrlHistoryStg, you have to write at least the following code:

#include <urlhist.h>    // Definition of IUrlHistoryStg
#include <shlguid.h>    // Definition of SID_SUrlHistory
// somewere inside a function
   IUrlHistoryStgPtr stg;

Or, you can use one of various other ways to create a COM object. Now, if you want to enumerate all the history entries, the code is like the following:

ULONG ures;
while (en->Next(1, &url, &ures) == S_OK)
   if (!(url.dwFlags & STATURL_QUERYFLAG_NOURL))
      if (!(url.dwFlags & STATURL_QUERYFLAG_NOTITLE))

Pay attention on CoTaskMemFree. MSDN states “The calling function must free this parameter.”, but does not provide any clue about how to do it.

In addition to this short article intended for a fast overview, I attach the source code of a simple command-line tool that does most basic operations with IE history. I guess it will be useful for home PC administration purposes. The source is a single C++ file and VC.NET2005 project. For other environments, I don’t see a problem in creating Win32 Console project with the given single source file.

The code in the sample tool use the IUrlHistoryStg interface to perform all the operations. The functions used are IUrlHistoryStg::EnumUrls, IUrlHistoryStg::AddUrl, and IUrlHistoryStg::DeleteUrl.

External Links

More by Author

Must Read