PRB: DeleteUrl() Does Not Delete the Internet Explorer History Folder Entry

Article translations Article translations
Article ID: 327569
Expand all | Collapse all

On This Page


After you call the IUrlHistoryStg::DeleteUrl method for a URL, the URL entry still appears in the Internet Explorer History Shell folder.


Use the IContextMenu::InvokeCommand method to delete the items. This is similar to manually deleting the item. The disadvantage to this method is that you cannot disable the confirmation dialog box that appears.

The source code that follows demonstrates the resolution by deleting the first, top-level History Shell folder. Typically, this is the oldest day in the history (for example, Tuesday). You can modify the code to delete a more specific item.
// Error checking minimized for clarity.
void DeleteUrlFromHistoryShell()

	// Call this if needed.
	CoInitialize( NULL );
	IShellFolder* pDesktopFolder = NULL;
	IMalloc* pMalloc = NULL;

	hr = ::SHGetMalloc(&pMalloc);

	// Get desktop folder.
	hr = ::SHGetDesktopFolder(&pDesktopFolder);

	// Get the history folder.
	ITEMIDLIST* pidlHistoryFolder = NULL;
	hr = ::SHGetSpecialFolderLocation(NULL, CSIDL_HISTORY, &pidlHistoryFolder);

	// Get the IShellFolder of the history folder.
	IShellFolder* pHistoryFolder = NULL;
	hr = pDesktopFolder->BindToObject(pidlHistoryFolder, NULL, IID_IShellFolder, (void**)&pHistoryFolder);

	// Enumerate the history items.
	IEnumIDList* pHistoryEnum = NULL;
	hr = pHistoryFolder->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pHistoryEnum);

	ULONG fetched = 0;

	hr = pHistoryEnum->Next(1, &pidl, &fetched);

	if (SUCCEEDED(hr))
		const ITEMIDLIST* pidl2 = pidl;

		// Get the IContextMenu interface.
		IContextMenu* pContextMenu = NULL;
		hr = pHistoryFolder->GetUIObjectOf(NULL, 1, &pidl2, IID_IContextMenu, NULL, (void**)&pContextMenu);

		if (SUCCEEDED(hr))
			CMINVOKECOMMANDINFO pCommandInfo = { 0 };

			pCommandInfo.cbSize = sizeof(CMINVOKECOMMANDINFO);
			pCommandInfo.lpVerb = _T("delete");
			pCommandInfo.fMask = CMIC_MASK_FLAG_NO_UI; // has no effect
			hr = pContextMenu->InvokeCommand(&pCommandInfo);




This behavior is by design.

More information

The IUrlHistoryStg2::ClearHistory method clears the deleted history items from the Internet Explorer History Shell folder and internally. DeleteUrl is not designed to delete the Internet Explorer History Shell folder entries. Because many internal functions rely on this method, its behavior cannot be changed.

Steps to Reproduce the Behavior

  1. Create a console application, and then add the following code:
    #include <atlbase.h>
    #include <shlobj.h>
    #include <UrlHist.h>
    // Error checking minimized for clarity.
    int main(int argc, char* argv[])
    	IUrlHistoryStg2* pUrlHistoryStg2 = NULL;
    	HRESULT hr = CoCreateInstance(CLSID_CUrlHistory,
    		NULL, CLSCTX_INPROC, IID_IUrlHistoryStg2,
    	IEnumSTATURL* pEnumURL;
    	hr = pUrlHistoryStg2->EnumUrls(&pEnumURL);
    	ULONG pceltFetched;
    	suURL.cbSize = sizeof(suURL);
    	hr = pEnumURL->Reset();
    	while((hr = pEnumURL->Next(1, &suURL, &pceltFetched)) == S_OK)
    		hr = pUrlHistoryStg2->DeleteUrl(suURL.pwcsUrl, 0);
    		printf("\"%s\" deleted.\n", W2T(suURL.pwcsUrl));
  2. Build and run the application. Notice that the first time that you run the code, your history is deleted. The second time that you run the code, the previous history entries are not there anymore.


For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
IContextMenu Interface

IUrlHistoryStg::DeleteUrl Method
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:


Article ID: 327569 - Last Review: June 19, 2014 - Revision: 3.0
kbprb kburlmon KB327569
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from