PDA

View Full Version : Unpin Taskbar Item



Jonathan Kay
01-08-2013, 06:57 AM
Hi,

I recently had to rename one of our application .exe files. Whilst I replaced the standard 'shortcut', for many users the application had found it's way into the 'frequently used' pin list. :(

I would like the installer to unpin the old shortcut to avoid this.

SB provides the 'Pin to Taskbar' function, but how about unpinning?

TIA,
Jonathan.

linder
01-08-2013, 07:03 AM
Jonathan,

Taken from the documentation: "This script function makes use of undocumented Windows 7 functions, so please use it at your own risk!"

That's why it is not recommended to use this function at all. "Pin" is always a per-user Windows task, but you do a per-machine install. In other words, Windows does not support what you are trying to do. Once it made it into a "per-user" area (e.g. frequently used for a specific user) you do not have access to it from an elevated running app.

Friedrich

linder
01-08-2013, 07:06 AM
BTW, and if you are not using the "Pin to Taskbar..." script function (not clear from the original post), there is no "Unpin from Taskbar" function to programmatically unpin an per-user item. You do not have access to the frequently used per-user area!

Friedrich

Jonathan Kay
01-08-2013, 07:28 AM
I'm not using the 'Pin to Taskbar'. The program just got there because it was run frequently enough. The trouble is I changed the .exe name, and even if the old exe is removed it still manages to run the old version (from somewhere, I didn't research that).

What I want to do is described here:

http://msdn.microsoft.com/en-gb/library/windows/desktop/bb774817(v=vs.85).aspx

This is the recommended method for uninstallers. I'm guessing (I didn't try) that the O/S is smart enough to remove the shortcut from the 'per user' list once this has been called from an elevated app. If it doesn't, uninstalled programs would still be appearing in the frequently used list (maybe they do but that just seems wrong!).

If this function does work and removes the per user shortcut then I would like this to be a function in SB.

Does that make sense?

linder
01-08-2013, 08:44 AM
Jonathan,

We have to do some research for a future build. As I understand it now, you have a "per-machine" Shortcut and this appears in a per-user "frequently used list" because it was run frequently enough. I am not sure if the IStartMenuPinnedList::RemoveFromList method can be used to handle this scenario.

BTW, how did you remove the Shorcut? Did you permanently remove it from the per-machine shortcut folder?

Friedrich

Jonathan Kay
01-08-2013, 09:32 AM
Hi Friedrich,

Yes, the standard shortcut is 'per-machine' but it was run often enough to get in the per-user frequently used items list.

The support calls came in because the name of an executable was changed but it still ran the old version (when clicking on the frequently used shortcut). This is inspite of me removing the old exe in the installer.

I didn't remove the shortcut myself, I just got the users to right-click and choose 'Remove from this List' (I guess that calls the function I linked internally). When they used the 'standard' short-cut it worked fine (and of course, this will eventually get promoted to the frequently used list).

I did try running the uninstaller, and that *does* remove the icon from the per-user frequently used list. This makes me think that the function I linked will work just fine.

In hindsight, I should have changed the installer so it ran the uninstaller first. But it's too late for that now - all that will happen is that the new icon gets removed leaving the old one still present!

That is the reason for my request.

Thanks,
Jon.

linder
01-08-2013, 10:55 AM
Jon,

Aha, okay. That was your problem. You have to permanently remove the shortcut file itself!

The IStartMenuPinnedList method you mentioned should be called BEFORE the Shortcut is permanently removed :) So if you do not remove the .lnk file then the method does nothing <g>.

In other words, just use the "Delete File(s)..." script function to remove the .lnk shortcut and you are done.

Friedrich

Jonathan Kay
01-09-2013, 02:00 PM
Hi Friedrich,

Can you expand on that. I don't see how it helps me.

If I remove <appname>.lnk then I'm just removing the current shortcut, only for SB to add it again.

Would a 'refresh desktop' in-between force removal from the (pre-user frequently used) pinned list if the shortcut has gone? I'm not so sure.

Many thanks,
Jon.

linder
01-10-2013, 12:47 AM
Hi Jon,

A "Refresh Desktop" command just sends a redraw event to the Desktop. If you permanently remove a Shortcut (.lnk) then Windows does all the house cleaning. There is no way to handle this programmatically from an application.

BTW, in the previous post you said:

"I did try running the uninstaller, and that *does* remove the icon from the per-user frequently used list. This makes me think that the function I linked will work just fine."

The uninstall does exactly the same. It calls the "Delete File(s)..." function to remove the .lnk.

Friedrich

Jonathan Kay
01-10-2013, 12:24 PM
Hi Friedrich,

I shall test this, but what concerns me is that something else needs to happen between me deleting the old link and creating a new one (with exactly the same name). The name of the .lnk file does not change, it's the name of the exe file (referred to in the lnk) that's different. However, the frequently used pinned item refers to the old exe name.

What you seem to be suggesting is to do a Delete File first (on appname.lnk) but as soon as the install is done appname.lnk will be recreated (with the same name). This isn't much different to the installer replacing the .lnk file (which is what happens now), but that didn't make any change to the frequently used pinned item.


Jon.

linder
01-11-2013, 02:36 AM
Hi Jon,

When the uninstall deletes a Shortcut (.lnk) then it calls the "Delete File(s)..." script function to remove the Shortcut file. The "Delete File(s)..." script function is a wrapper around the original DeleteFile Windows API.

So if you make use of "Delete File(s)..." to programmatically remove a Shortcut then there is absolutely no difference (from the technical point-of-view) between the approaches.

Friedrich