views:

1165

answers:

5

As in title, is there any Win32 API to do that? Thanks in advance.

A: 

this folder contains shortcut of pinned application

C:\Users\Your-User-Name\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

tsurahman
Ummm... I just tried pinning an item to the taskbar and this folder wasn't created. Are you sure that it works for Windows 7?
Larry Osterman
+7  A: 

Don't do this.

I'm 99% sure there isn't an official API for it, for exactly the same reason that there wasn't programmatic access to the old Start Menu's pin list.

In short, most users don't want programs putting junk in their favorites, quick launch, taskbar, etc. so Windows doesn't support you doing as such.

Kevin Montrose
Kevin's answer is the right one :). Just resist the pressure from your customer.
Larry Osterman
A: 

I found there is no offical API to do that, but someone has do it through VBScript. http://blog.ananthonline.net/?p=37 Thanks.

Yigang Wu
+1  A: 

In the comments of a Code Project article it says all you have to do is create a symbolic link in the folder "C:\Users\Username\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar".

But it appears to generally be unsociable practice, as the other comments here have noted.

tdyen
A: 

You can pin/unpin apps via Windows Shell verbs:
http://blogs.technet.com/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx

For API, there is a script-friendly COM library for working with the Shell:
http://msdn.microsoft.com/en-us/library/bb776890%28VS.85%29.aspx

Here is an example written in JScript:

// Warning: untested and probably needs correction
var appFolder = "FOLDER CONTAINING THE APP/SHORTCUT";
var appToPin = "FILENAME OF APP/SHORTCUT";
var shell = new ActiveXObject("Shell.Application");
var folder = shell.NameSpace(appFolder);
var folderItem = folder.ParseName(appToPin);
var itemVerbs = folderItem.Verbs;
for(var i = 0; i < itemVerbs.Count; i++)
{
    // You have to find the verb by name,
    //  so if you want to support multiple cultures,
    //  you have to match against the verb text for each culture.
    if(itemVerbs[i].name.Replace(/&/, "") == "Pin to Start Menu")
    {
        itemVerbs[i].DoIt();
    }
}
Brandon Payton