Command line tool to manage Windows 7 Libraries, with source code


A customer asked if there was a command-line tool for managing Windows 7 Libraries so that they could create and deploy libraries across their organization.

Not only is there such a tool, it even comes with source code.

The Shell Library Command Line Sample shows how to manage Windows 7 libraries programmatically via the IShell­Library interface. And it's actually a useful program on its own.

Usage: shlib.exe SUBCOMMAND

Displays and modifies the attributes of Shell Libraries.

Supported commands:
  create      Creates a library at the specified path.
  info        Prints info about the given library.
  enum        Enumerates the folders in the library.
  setattrib   Modifies the attributes of the library.
  add         Adds the specified folder to the specified library.
  remove      Removes the specified folder from the library.
  setsaveloc  Sets the default save location of the library.
  resolve     Resolves the specified folder in the library.
  resolveall  Resolves all locations in the library in bulk.
  manage      Displays the Manage Library Dialog for the library.

For example, to see all the folders that are part of your Documents library, use the command

shlib enum FOLDERID_DocumentsLibrary

Each of the commands has further sub-options.

Usage: create shlib.exe [OPTIONS]  [...]

Creates a library at the specified path.

Options:
 -create[:ARG]       Specifies that a new library should be created.
   <none>              Fail if the library already exists.
   overwrite           Overwrite any existing library.
   uniquename          Generate a unique name in case of conflict.

The library may be specified by a file system path,
or by a KNOWNFOLDERID (e.g. "FOLDERID_DocumentsLibrary").

And the source code shows how to perform each of these actions programmatically.

The IShellLibrary interface is also supported by the Windows API Code Pack for .NET, so you C# folks can use it too.

(One thing I noticed that is missing from the sample is a seticon command. Shouldn't be hard to implement. You just call IShell­Library::Set­Icon.)

Comments (14)
  1. laonianren says:

    If anyone else was wondering "what's a library?":

    "Libraries aggregate items from local and remote storage locations into a single view in Windows Explorer."

    msdn.microsoft.com/…/dd798389%28v=vs.85%29.aspx

  2. Adam Rosenfield says:

    @laonianren: Thanks.  My reaction to the title was "why does someone need a tool for managing static libraries (.lib files)?  Are the standard file system tools and source control not good enough?".

  3. creaothceann says:

    My reaction to the title was "why does someone need a tool for managing DLLs?"

  4. Dan Bugglin says:

    My reaction was "Oh cool, I can manage folder Libraries from the command line!"

    Because you know it does say "Windows 7 Libraries", and one of the bullet points for Windows 7 new features was Libraries… they are prominently featured in Explorer too, near the top of the tree view on the left, if you managed not to hear about them at all…

  5. Adam Rosenfield says:

    @The MAZZTer: Huh, somehow that entirely flew by me.  I certainly noticed the Documents, Music, Pictures, and Videos (virtual?) directories, but I never noticed that their common parent directory was named Libraries.

  6. John Ludlow says:

    @Adam, Me too. I knew they were called libraries, but I use them so rarely that it's not at the forefront of my mind, so it's not the first thing I think of when I hear "Library". At first I assumed it was some tool to examine libraries built against the Win7 SDK.

    However, the actual meaning does make more sense

  7. TKW says:

    Nitpick:

    Usage: create shlib.exe [OPTIONS]  […]

    or

    Usage: shlib.exe create [OPTIONS]  […] ?

    [I thought I copied it straight from the app output, but now I'm not so sure… And I'm too lazy to go re-download the app. So you figure it out. -Raymond]
  8. Steve says:

    What is the difference between that link and this one? msdn.microsoft.com/…/dd940379

    [None. -Raymond]
  9. Joshua says:

    [None. -Raymond]

    Nice.

  10. AC says:

    [And I'm too lazy to go re-download the app. So you figure it out. -Raymond]

    Are you still on vacation?

    That doesn't sound like the "are you sure you're not a robot" obsessive Raymond we're used to.

    (Hint: This is not intended as an offense)

  11. John says:

    Say, this sounds like an interesting app but I'm no programmer and don't have access to VS either. Raymond, can you please link to a compiled binary?

  12. John says:

    P.S. Found a compiled version elsewhere, but not sure I trust it.

  13. Joshua says:

    @John: I wish I could get away with saying lack of access to compilers by end users is how viruses spread but that's not the case.

  14. Gabest says:

    Libraries, that thing in explorer which pushes the ones I want to click out of the view.

Comments are closed.