Windows 7 - Taskbar - Pin or Unpin Program Links

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

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

相关标签:
8条回答
  • 2021-01-12 04:20

    Just to put some links on the info as microsoft now offer an official documentation on "Taskbar Extensions" :

    A small set of applications are pinned by default for new installations. Other than these, only the user can pin further applications; programmatic pinning by an application is not permitted.

    So Kevin Montrose answer is the correct one : DON'T.

    0 讨论(0)
  • 2021-01-12 04:27

    this folder contains shortcut of pinned application

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

    0 讨论(0)
  • 2021-01-12 04:28

    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.

    0 讨论(0)
  • 2021-01-12 04:35

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

    0 讨论(0)
  • 2021-01-12 04:36

    I'm trying to implement a VirtuaWin (opensource virtual desktop software) plugin that allows me to pin different buttons to different virtual desktops. Completely valid reason to use this.

    Found the way to pin/unpin it already:

    Following code snippet is taken from Chromium shortcut.cc file, nearly unchanged, see also the ShellExecute function at the MSDN

    bool TaskbarPinShortcutLink(const wchar_t* shortcut) {
      int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarpin", shortcut,
          NULL, NULL, 0));
      return result > 32;
    }
    
    bool TaskbarUnpinShortcutLink(const wchar_t* shortcut) {
      int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarunpin",
          shortcut, NULL, NULL, 0));
      return result > 32;
    }    
    // Copyright (c) 2012 The Chromium Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    

    Seems pretty straightforward if you know the shortcut. For me though this is not sufficient, I also need to iterate over existing buttons and unpin and repin them on different desktops.

    0 讨论(0)
  • 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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题