TIP: IE URL History Tool (Yet Another) | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Apr 10, 2007
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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;
   stg.CreateInstance(SID_SUrlHistory);

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:

IEnumSTATURL *en;
stg->EnumUrls(&en);
STATURL url;
ULONG ures;
while (en->Next(1, &url, &ures) == S_OK)
{
   HandleSingleURL(&url);
   if (!(url.dwFlags & STATURL_QUERYFLAG_NOURL))
      CoTaskMemFree(url.pwcsUrl);
      if (!(url.dwFlags & STATURL_QUERYFLAG_NOTITLE))
         CoTaskMemFree(url.pwcsTitle);
}
en->Release();

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.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.