簡體   English   中英

如何以編程方式將應用程序固定到任務欄

[英]How to pin application into taskbar programmatically

我已經嘗試過這段代碼,它可以很好地從 Windows 10 中的任務欄取消固定應用程序,但不能將應用程序固定到任務欄中。

public static void PinUnpinTaskbar(bool pin)
{
    string l_strFilePath = System.Reflection.Assembly.GetEntryAssembly().Location;
    if (!File.Exists(l_strFilePath)) throw new FileNotFoundException(l_strFilePath);
    int MAX_PATH = 255;
    var actionIndex = pin ? 5386 : 5387; // 5386 is the DLL index for"Pin to Tas&kbar", ref. http://www.win7dll.info/shell32_dll.html
                                         //uncomment the following line to pin to start instead
                                         //actionIndex = pin ? 51201 : 51394;
    StringBuilder szPinToStartLocalized = new StringBuilder(MAX_PATH);
    IntPtr hShell32 = LoadLibrary("Shell32.dll");
    LoadString(hShell32, (uint)actionIndex, szPinToStartLocalized, MAX_PATH);
    string localizedVerb = szPinToStartLocalized.ToString();

    string path = Path.GetDirectoryName(l_strFilePath);
    string fileName = Path.GetFileName(l_strFilePath);

    // create the shell application object
    dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
    dynamic directory = shellApplication.NameSpace(path);
    dynamic link = directory.ParseName(fileName);

    dynamic verbs = link.Verbs();
    for (int i = 0; i < verbs.Count(); i++)
    {
        dynamic verb = verbs.Item(i);
        if (verb.Name.Equals(localizedVerb))
        {
            verb.DoIt();
            return;
        }
    }
    return;
}

在您的解決方案中看不到任何錯誤,也嘗試了幾次但動詞不再存在。 經過一些研究,我發現了這個:

更新 KB3093266 刪除了 shell.Application 對象 'taskbarpin' 動詞

更新 KB3093266 刪除了用於添加任務欄 pin 項目 pin 的 shell.Application 對象“taskbarpin”動詞

它很可能被 KB3093266 取代的更新之一破壞


而這個(Powershell 但同一個庫): 在 Windows 10 中固定到任務欄失敗

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM