Programmatically adding a folder to a shell library (e.g., the Music library)

I wrote a selfhost tool which allows me to add a folder (for example, C:music) to a shell library (for example, the Music library.)

This was before I found out about the shlib shell library sample which Raymond Chen blogged about.  If you’re looking for a sample on how to manipulate shell libraries, prefer that one to this.

Pseudocode:

CoInitialize
pShellLibrary = SHLoadLibraryFromKnownFolder(library GUID)
SHAddFolderPathToLibrary(pShellLibrary, path)
pShellLibrary->Commit()
CoUninitialize

Usage:

>shelllibrary
shelllibrary add <path> to <library>
<path> must already exist
<library> must be one of:
documents
music
pictures
videos
recorded tv
>shelllibrary add C:\music to Music
Added C:\music to Music library

Browse source

Download shelllibrary.exe

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s