Download source files - 24 Kb
Download demo project - 21 Kb
Introduction
Recently I have been working on a project that involved
getting the list of favorites (aka Bookmarks) in Internet Explorer. Microsoft
does provide an API to dump all the favorites in a text file that follows Netscape's
bookmark format. But that text file did not serve my purpose. First I needed a
parser that could extract all the information from that file and secondly, the
method call ImportExportFavorites
on IShellUIHelper
interface requires the user
to select if they want to dump the favorites or not.
This gave me a reason to search for alternatives. The
answer was using the shell programming API. Favorites are stored in a user's
profile as regular folders and files. Therefore I could use the file attributes
to extract all the information that I needed, namely creation, modified and last
access dates, URL, description of the favorite. During the search I came across
a Microsoft article that described how to get started with this. With the help
of that article and some of my own ideas I came up with this COM object, IFavoriteEngine
,
that does the trick for me.
The implementation shows the use of the shell APIs and some COM concepts, and prepares
the complete enumeration of Favorites on the system. This COM object has just two methods:
LoadFavorites | This method accesses all the Favorites
on the system and prepares the enumeration list. |
GetFavoritesObjList</code<</td><td>This method returns
the enumeration that was created by the <code>LoadFavorites method call. |
GetFavoritesObjList
returns another COM object
IFavoritesObjList
. This object has its own methods that can be called to
extract all the information. This object returns another COM object
IFavoriteObject
. This is the object that contains the details e.g. dates,
description, etc.
The SHGetSpecialFolderLocation
API is used to get the list of
all the favorites in a user's profile. The second parameter to this call is
CSIDL_FAVORITES
, indicating that it should fetch all the Favorites from a user
profile. To get the other attributes of the favorites file and folders, the Win32
API GetFileAttributesEx
has been used.
I have included a simple Win32 console application to show
how the IFavoritesEngine
COM object can be used to get all
the favorites on a
system. The code has been written and compiled using VC++6 (SP4) on Windows
2000, Adv Server (SP1). I have only been testing the debug build. So if you
find any problems with release configuration of the project, pleas e let me
know.