在Visual Studio安装项目的任务栏中固定应用程序

时间:2012-09-01 22:40:30

标签: visual-studio-2010 setup-project

当Mozilla Firefox安装时,安装程​​序会在任务栏中将Mozilla固定,我也想要它!

我正在使用VS2010

2 个答案:

答案 0 :(得分: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文件的路径

在固定/取消固定任务栏的情况下,将“Pin to Start Menu”替换为“pin to taskbar” 和“从开始菜单取消固定”到“从任务栏取消固定”

所有固定文件都位于

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

本规范适用于Windows7美国英语。

干杯!

答案 1 :(得分: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控件和自动化”参考

并感谢@James Johnston - 他的original post