0

Mozilla Firefoxがインストールされると、インストーラーがMozillaをタスクバーに固定します。私もそれが欲しいです!!!

VS2010を使用しています

4

2 に答える 2

2

タスクバーとスタートメニューにピン留め/ピン留め解除するためのVb.netコードスニペット。(フレームワーク 3.5)

Dim shellApplication As Shell = New ShellClass()

Dim directoryName As String = Path.GetDirectoryName(filePath)
Dim fileName As String = Path.GetFileName(filePath)

Dim directory As Shell32.Folder = shellApplication.[NameSpace](directoryName)
Dim link As FolderItem = directory.ParseName(fileName)

Dim verbs As FolderItemVerbs = link.Verbs()
For i As Integer = 0 To verbs.Count - 1
  Dim verb As FolderItemVerb = verbs.Item(i)
  Dim verbName As String = verb.Name.Replace("&", String.Empty)   
 If (verbName.Equals("Pin to Start Menu")) Or (verbName.Equals("Unpin from Start Menu")) Then

    verb.DoIt()
  End If
Next
shellApplication = Nothing

'filePath は、タスクバーを固定/固定解除する .exe ファイルのパスです

タスクバーの固定/固定解除の場合、「スタート メニューに固定」を「タスクバーに固定」に、「スタート メニューから固定解除」を「タスクバーから固定解除」に置き換えます。

固定されたすべてのファイルは、

C:\Users\%LoggedIn_User_Name%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned 

このコードは Windows7 US English で動作します。

乾杯!

于 2012-10-18T06:36:12.650 に答える
0
private static void PinUnpinTaskBar(string filePath, bool pin) {
    if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);

    // create the shell application object
    Shell shellApplication = new ShellClass();

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

    Folder directory = shellApplication.NameSpace(path);
    FolderItem link = directory.ParseName(fileName);

    FolderItemVerbs verbs = link.Verbs();
    for (int i = 0; i < verbs.Count; i++) {
        FolderItemVerb verb = verbs.Item(i);
        string verbName = verb.Name.Replace(@"&", string.Empty).ToLower();

        if ((pin && verbName.Equals("pin to taskbar")) || (!pin && verbName.Equals("unpin from taskbar"))) {

            verb.DoIt();
        }
    }

    shellApplication = null;
}

「Microsoft Shell Controls And Automation」リファレンスを必ず含めてください

@James Johnston に感謝します - 彼の元の投稿

于 2012-09-01T22:44:51.947 に答える