Introduction

The new taskbar in Windows 7 provides a feature to 'pin' programs to the taskbar. Pinned taskbar buttons will be visible in the taskbar even if the program is not running. This article provides functions to check if a program or window is pinned or not.

Background

I use this code for a virtual desktop manager. If a program is pinned, I do not need to show/hide the taskbar buttons during desktop change.

How it works

All currently pinned programs have a symbolic link in the folder C:\Users\Username\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar. My solution to check if a program is pinned or not is to look if one of the symbolic links is pointing to the program's executable:

get the first symbolic link from the '..\TaskBar' folder

retrieve the path to the exe the symbolic link is pointing to

compare the path with the path I am looking for, if equal: stop and return true

if not: get the next symbolic link

I put the code in a class. The class provide these two static methods:

TaskbarPinUtility::checkIfWindowIsPinned() gets the path to the executable of the window with the function getWindowFileName() (look in the example code for the implementation) and then calls TaskbarPinUtility::checkIfProgramIsPinned():

//check if the executable of a window ID is pinned
result TaskbarPinUtility::checkIfWindowIsPinned(HWND window)
{
result res=no;
if (!IsWindow(window))
{
return error;
}
//path to the executable of the window
wstring *pathToExe=getWindowFileName(window);
if (pathToExe==NULL)
{
return error;
}
//use this path to search for a link...
res=checkIfProgramIsPinned(*pathToExe);
delete pathToExe;
return res;
}

TaskbarPinUtility::checkIfProgramIsPinned() loops through all links in the ..\TaskBar folder until a symbolic link is pointing to pathISearch: