Windows 7 - Taskbar - Pin or Unpin Program Links

后端 未结 8 1524
不思量自难忘°
不思量自难忘° 2021-01-12 04:13

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

8条回答
  •  醉话见心
    2021-01-12 04:38

    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();
        }
    }
    

提交回复
热议问题