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

Source and binaries attached.