Pin and Un-pin items to/from the Windows 7 taskbar

One of the things I wanted to do with Lyre (my Windows 7 taskbar-based MP3 player), was to

  1. Figure out if a given executable is pinned to the taskbar
  2. Un-pin it from the taskbar
  3. Pin it back to the taskbar

During my searches, I found this blog post that says programmatic access to pinning and un-pinning has been disabled for a similar reason. I did find a couple of posts here and here, showing how to use a small shell script to pin and un-pin items.

The idea is rather simple, really. The verbs “Pin to Tas&kbar” and “Unpin from Tas&kbar” (the ampersand is the shortcut, it is required to directly execute the verb) are available on a shell link object. Executing one or the other will pin/unpin the specified shortcut.

How do we find out if an item is pinned to the taskbar? For that, we need to look in “%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\”, where these pinned “shortcuts” live. If we find a particular executable’s shortcut there, that means it’s pinned.

Now that we know what we need to do, the doing is quite simple, really.

Tell if a shortcut is pinned to the taskbar

  1. Examine each shortcut in the user’s pinned items path.
  2. If the path (or filename?) matches the executable you’re looking for, return true.
  3. Otherwise return false.

Pin/Unpin items to/from the taskbar

  1. Create a temporary shortcut to the executable we want to pin/unpin
  2. Create and execute a shell script that runs the appropriate verb (”Pin to Tas&kbar” or “Unpin from Tas&kbar“)
  3. We’re done!

Attached is a single .cs file that contains a class called Windows7TaskbarExtensions.cs.

Note: I’ve used the ShellShortcut classes by Mattias Sjögren
The Image



 

Other Recent Posts