0

When Mozilla Firefox installs, the installer pins Mozilla in taskbar, and I want it too!!!

I'm using VS2010

TYeeTY
  • 577
  • 8
  • 16
  • Microsoft doesn't recommend you pin yourself to the taskbar. http://blogs.msdn.com/b/oldnewthing/archive/2014/12/30/10583474.aspx – Abhishek Jan 20 '15 at 20:28

2 Answers2

2

Vb.net Code snippet for Pin to/Unpin from Task Bar and Start Menu. (framework 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 is the path of .exe file that you want to pin/Unpin taskbar

In Case of Pinning/Unpinning Taskbar replace "Pin to Start Menu" with "pin to taskbar" and "Unpin from Start Menu" to "unpin from taskbar"

All the pinned files resides in the

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

This Code is working on Windows7 US English.

Cheers!

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
Abdul
  • 854
  • 1
  • 9
  • 11
  • I am a C# programmer but this is not the matter. I want installer do this for me, so where am I should write these codes? – TYeeTY Oct 18 '12 at 16:23
  • if you get an error like `Interop type 'ActiveHomeScriptLib.ActiveHomeClass' cannot be embedded. Use the applicable interface instead.` you should set the property "Embed Interop Types" for shell32 assembly to "False". https://stackoverflow.com/questions/2483659/interop-type-cannot-be-embedded – PeterCo Feb 15 '18 at 13:58
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;
}

be sure to include the "Microsoft Shell Controls And Automation" reference

and say thanks to @James Johnston - his original post

Community
  • 1
  • 1
mc_fish
  • 493
  • 3
  • 10
  • I want Installer pin the app, not app it's self. where am I should enter this code?! :@ – TYeeTY Sep 01 '12 at 22:53
  • it would pin a .lnk(shorcut) to the taskbar, if you want the installer to do it, run a script http://blogs.technet.com/b/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx – mc_fish Sep 01 '12 at 23:45