Visual studio 2010 visual studio安装项目中任务栏中的Pin应用程序

Visual studio 2010 visual studio安装项目中任务栏中的Pin应用程序,visual-studio-2010,setup-project,Visual Studio 2010,Setup Project,当Mozilla Firefox安装时,安装程序将Mozilla固定在任务栏中,我也想要它 我正在使用VS2010私有静态void PinUnpinTaskBar(字符串文件路径,bool pin){ private static void PinUnpinTaskBar(string filePath, bool pin) { if (!File.Exists(filePath)) throw new FileNotFoundException(filePath); // c

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

我正在使用VS2010

私有静态void PinUnpinTaskBar(字符串文件路径,bool pin){
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;
}
如果(!File.Exists(filePath))抛出新的FileNotFoundException(filePath); //创建shell应用程序对象 Shell shellApplication=新的ShellClass(); string path=path.GetDirectoryName(filePath); 字符串fileName=Path.GetFileName(filePath); 文件夹目录=shellApplication.NameSpace(路径); FolderItem link=directory.ParseName(文件名); FolderItemVerbs=link.verbs(); for(int i=0;i
请确保包含“Microsoft Shell控件和自动化”参考


感谢@James Johnston——他在任务栏和“开始”菜单中为Pin to/Unpin提供的

Vb.net代码片段。(框架3.5)

'filePath是要固定/取消固定任务栏的.exe文件的路径

在固定/取消固定任务栏的情况下,将“固定到开始菜单”替换为“固定到任务栏” 和“从开始菜单取消锁定”到“从任务栏取消锁定”

所有固定的文件都驻留在

C:\Users\%LoggedIn_User_Name%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned 
此代码在Windows7 US English上运行


干杯

我要安装程序pin的应用程序,而不是应用程序它的自我。我应该在哪里输入此代码?!:@它会将一个.lnk(shorcut)固定到任务栏上,如果你想让安装程序这么做,请运行一个脚本我是一个C#程序员,但这不是问题。我想让安装程序帮我完成这项工作,那么我应该在哪里编写这些代码呢?如果您遇到类似
Interop类型的错误,则无法嵌入'ActiveHomeScriptLib.ActiveHomeClass'。请改用适用的接口。
您应该将shell32程序集的属性“嵌入互操作类型”设置为“False”。Microsoft不建议您将自己固定在任务栏上。
C:\Users\%LoggedIn_User_Name%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned