0

I'm looking for a way to pin an exe and/or a shortcut into the Windows 8.1 Taskbar (not in the StartMenu) without depending on the verb name.

I did a research and I only can find code-examples like this that does not works because they are verb-name language dependant, this means it checks for a verb titled "Pin To Taskbar" and then invoke it, but that verb does not exists with English name in other languages, for example in Spanish 'Pin To Taskbar' is translated as 'Anclar a la barra de tareas', I really hope that invoking a verb parsing its verb-name is not the unique way to perform this task.

Then I wonder whether the Microsoft's WindowsAPICodePack library maybe provides a way to perform this in a more efficient way, or at least in a way that really will works.

Or maybe using the Windows API SendMessage function?

Any ideas?

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 6
    Keep in mind that applications are not supposed to do this. It isn't up to you to decide that your application really should be pinned if the user doesn't do so himself. – Harry Johnston Oct 09 '14 at 02:40
  • @Harry Johnston thankyou for the suggestion, but I have in mind to develop a mini-tool for my personal usage that should pin/unpin external applications selecting the desired app through a OpenFile-Dialog, is to manage my environment. thanks for your comment – ElektroStudios Oct 09 '14 at 02:59
  • I came across the same requirement although I was using WiX Installer. In the end I gave up and let users make the decision. Just thought I'd share [my 2 cents in the WiX context and the event you can track down the registry keys and etc](http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/use-wix-to-pin-to-taskbar-and-pin-to-start-menu-td5518811.html) (maybe get out process monitor). – Jeremy Thompson Oct 09 '14 at 03:08
  • If this is for personal use, then you already know what language(s) you need to support, so what's the problem? – Harry Johnston Oct 09 '14 at 03:12
  • @Harry Johnston the only reason is beacuse as a developer I would like to do things right, I just wanted to know the efficient way which does not require invoking a verb knowing the verb name (if possibly), I will not write poor methodologies even if it is only for my usage. sorry for my English. – ElektroStudios Oct 09 '14 at 03:17
  • -1 For your rude comments ("I clearly explained...", and "did you read my question?") – Ergwun Oct 09 '14 at 04:01
  • you may want to have a look at [Where is the list of pinned start menu and taskbar items stored in Windows 7](http://superuser.com/questions/171096/where-is-the-list-of-pinned-start-menu-and-taskbar-items-stored-in-windows-7) – pushpraj Oct 09 '14 at 04:03
  • @Ergwun I'm not rude, anyways English is not very good, but I just asked a clear question where I clearlly explained that thing, if an user posts an answer that does not match the question and with an unofficial comment of the past decade it does not help to me or to any other who reads the question in search of a possible solution. thanks for your comment. – ElektroStudios Oct 09 '14 at 06:59
  • @pushpraj thanks for comment, but unfortunately (as an user has pointed in a comment of that answer) putting your own shortcuts in that directory does not take any effect. – ElektroStudios Oct 09 '14 at 07:45
  • There is no official way to pin applications to taskbar, so you will need to rely on those verbs if you would like to do such thing. Those verbs are stored in the shell32.dll library resource string table. I've made [`a script`](http://stackoverflow.com/a/25066024/960757) for Inno Setup (so it's in Pascal Script), but you may take a look at the `TryGetVerbName` function which reads the verb names from that string table. I think in C# you will need to use those Windows API functions as well. – TLama Oct 09 '14 at 09:53
  • 1
    Doing this is unsupported. You have a functional answer below. It may break in future Windows versions. Good Luck! – David Crowell Oct 09 '14 at 15:54

3 Answers3

2

Why is there no programmatic access to the Start menu pin list?

In Windows XP we intentionally did not give programmatic access to the bold list of items at the top of the Start menu (the "pin list"). The pin list is for users to put their favorite icons. It is not the place for a program to decide unilaterally, "I am so cool. I am your favorite icon. I just know it. So I'll put myself there because, well, I'm so cool."

Because we knew that the moment we let people mess with the pin list, everybody would install themselves into it and it would become meaningless (and annoying).

What's particularly galling are the programs that, as part of their install, decide that they are so cool they want to be everywhere to make sure you don't miss out on the coolest most amazing program ever written in the history of mankind, so they go into the Start menu, into the Fast items, onto the desktop, into the Quick Launch, onto your Favorites, take over as your default autoplay handler, and even hang out as an icon next to the clock on the taskbar just in case you somehow missed all those other places - and each time you run them, they go and recreate those icons and settings in case you "accidentally lost them".

I hate those programs.


Looks like it is possible with the Microsoft-Windows-Shell-Setup on Win7 and above: TaskbarLinks

You are indeed correct about Verbs being language specific, here is the documentation stating this Pin Items to the Start Menu or Windows 7 Taskbar via Script:

The verbs for each action would have to be changed in the script for use with another language.

For automated deployments, some of these items can also be configured through an answer file on Windows Vista and higher. Windows 7 provides an unattend.xml setting to configure up to three Taskbar pinned items (see TaskbarLinks in Microsoft-Windows-Shell-Setup in the Automated Installation Kit documentation). And both Windows Vista and Windows 7 provide an unattend.xml setting to configure up to five “recently opened programs” on the Start Menu (StartPanelLinks in Microsoft-Windows-Shell-Setup). However, neither provide a way in unattend.xml to pin items to the Start Menu.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • 1
    I'm not asking for the Start Menu pin list, I'm asking for the TASKBAR pin/unpin, did you read my question?. – ElektroStudios Oct 09 '14 at 03:15
  • Yeah I read it and was tempted to delete my answer a minute ago as its too Start Menu (not TaskBar) focused. I just zero'd off your question. Unfortunately @JohnRah's method is the only other that I know of and its interesting he believes the `verb.Name` is language neutral. – Jeremy Thompson Oct 09 '14 at 03:33
  • Sorry but I missed the @JohnRa's method that you've mentioned, where is it, could you link it please?. PS: verb.name is not neutral but maybe there could be a way to access/use them through neutral names and that could be a great solution, I don't know. thanks for your help – ElektroStudios Oct 09 '14 at 03:40
  • Also, the ""documentation"" is from year 2003, I think is very irrelevant and maybe in this decade exists a Programmatically access through .NET framework class library (maybe, I don't know). – ElektroStudios Oct 09 '14 at 03:44
  • 2
    The comments on Start Menu pinning are equally applicable to taskbar pinning. – Harry Johnston Oct 09 '14 at 04:15
  • The `TaskbarLinks` component is part of the Microsoft-Windows-Shell-Setup which allows you to deploy a custom Windows installation. It's not for use by client applications. – TLama Oct 09 '14 at 17:03
0

In the code example you linked to you could look in the verb name for &k which is the keyboard shortcut for pinning to the taskbar. This doesn't change for different languages (I believe).

So change this in the code example:

If (verb.Name = "Pin to Tas&kbar") _

to this:

If (InStr(verb.name,"&k")>0) _

or something along those lines.

John Rah
  • 1,757
  • 1
  • 14
  • 13
  • 1
    In Spanish language `Taskbar` word is translated as `Barra de tareas`, any `K` char, and the accelerator key `&` appears before the `B` char of `&Barra`. I clearly explained that I'm looking for an alternative way to pin/unpin an element into TaskBar, not dependeing on verbs language localizations. thankyou anyways. – ElektroStudios Oct 09 '14 at 02:55
0

There is no official way to pin application to taskbar (at this time) as far as I know, so I think you will need to rely on that hacky way with verbs. But you don't need to (should not) hardcode them; they can be read from the shell32.dll library resource string table. Some time ago I wrote a script for Inno Setup which can pin app. to taskbar by using those verbs (based on this thread). One part of that code is reading necessary verbs from the shell32.dll library and that's what I've tried to translate to VB (that's my first time with VB.NET, so take the following code just as a proof of concept):

Module Module1

    Const SHELL32_STRING_ID_PIN_TO_TASKBAR As Int32 = 5386
    Const SHELL32_STRING_ID_UNPIN_FROM_TASKBAR As Int32 = 5387

    Private Declare Auto Function LoadLibrary Lib "kernel32.dll" ( _
        ByVal lpLibFileName As String _
    ) As IntPtr

    Private Declare Function FreeLibrary Lib "kernel32.dll" ( _
        ByVal hLibModule As IntPtr _
    ) As Boolean

    Private Declare Auto Function LoadString Lib "user32.dll" ( _
        ByVal hInstance As IntPtr, _
        ByVal uID As Int32, _
        ByVal lpBuffer As String, _
        ByVal nBufferMax As Int32 _
    ) As Int32

    Public Function TryGetVerbName(ByVal ID As Int32, ByRef VerbName As String) As Boolean
        Dim Handle As IntPtr
        Dim BufLen As Int32
        Dim Buffer As String = Space(255)

        Handle = LoadLibrary("shell32.dll")
        If Not Handle.Equals(IntPtr.Zero) Then
            Try
                BufLen = LoadString(Handle, ID, Buffer, Buffer.Length)
                If BufLen <> 0 Then
                    VerbName = String.Copy(Buffer)
                    Return True
                End If
            Finally
                FreeLibrary(Handle)
            End Try
        End If

        Return False
    End Function

    Sub Main()
        Dim VerbName As String = String.Empty

        If TryGetVerbName(SHELL32_STRING_ID_PIN_TO_TASKBAR, VerbName) Then
            Console.WriteLine("Verb name for pin to taskbar: " + VerbName)
        End If

        If TryGetVerbName(SHELL32_STRING_ID_UNPIN_FROM_TASKBAR, VerbName) Then
            Console.WriteLine("Verb name for unpin from taskbar: " + VerbName)
        End If

        Console.ReadLine()
    End Sub

End Module
Community
  • 1
  • 1
TLama
  • 75,147
  • 17
  • 214
  • 392