none
Pin application to Taskbar in win 10 programmatically C# RRS feed

  • Question

  • I would like to Pin application to <g class="gr_ gr_37 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep" data-gr-id="37" id="37">taskbar</g> in Windows 10 programmatically in c#.

    I tried this code, this code is unPinning the application but not Pinning the application.

    <pre>

    //PinUpin Application from Taskbar in Win7
            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
            internal static extern IntPtr LoadLibrary(string lpLibFileName);

            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
            internal static extern int LoadString(IntPtr hInstance, uint wID, StringBuilder lpBuffer, int nBufferMax);

            public static bool PinUnpinTaskbar(string filePath, bool pin)
            {
                if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);
                int MAX_PATH = 255;
                var actionIndex = pin ? 5386 : 5387; // 5386 is the DLL index for"Pin to Tas&kbar", ref. http://www.win7dll.info/shell32_dll.html
                                                     //uncomment the following line to pin to start instead
                                                     //actionIndex = pin ? 51201 : 51394;
                StringBuilder szPinToStartLocalized = new StringBuilder(MAX_PATH);
                IntPtr hShell32 = LoadLibrary("Shell32.dll");
                LoadString(hShell32, (uint)actionIndex, szPinToStartLocalized, MAX_PATH);
                string localizedVerb = szPinToStartLocalized.ToString();

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

                // create the shell application object
                dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
                dynamic directory = shellApplication.NameSpace(path);
                dynamic link = directory.ParseName(fileName);

                dynamic verbs = link.Verbs();
                for (int i = 0; i < verbs.Count(); i++)
                {
                    dynamic verb = verbs.Item(i);
                    if (verb.Name.Equals(localizedVerb))
                    {
                        verb.DoIt();
                        return true;
                    }
                }
                return false;
            }
            //end

    </pre>

    can any one please help me.

    How to Pin application to the taskbar in windows 10 programmatically in c#.

    Thanks


    Tuesday, October 9, 2018 8:57 AM

All replies

  • Add a shortcut to 

    "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"

    Tuesday, October 9, 2018 11:02 AM
  • Hi,

    thanks for posting here.

    Since your case is more related to c# code, I will move it to c# forum for better support.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 10, 2018 1:25 AM
    Moderator
  • Hi ABDUL SUBHAN MOHAMMED,

    For your question, please download the source file from the link below and do some change.

    http://alexweinberger.com/main/pinning-network-program-taskbar-programmatically-windows-10/

    Comment out the lines below.

      //if (args.Length < 1)
                //{
                //    Console.WriteLine("Syntax: PintoTB10 [/pin | /unpin] {program}");
                //    return 1;
                //}
    
                //bool pin = true;
                //string fileName = args[0];
    
                //if (args.Length == 2)
                //{
                //    if (args[0].ToLower() == "/pin") pin = true;
                //    else if (args[0].ToLower() == "/unpin") pin = false;
                //    else
                //    {
                //        Console.WriteLine("Syntax: PintoTB10 [/pin | /unpin] {program}");
                //        return 1;
                //    }
                //    fileName = args[1];
                //}

    And write the code in the Main method.

      string fileName = @"C:\Program Files (x86)\Internet Explorer\iexplore.exe";
                bool pin = true;

    In the code, I use IE for reference.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Friday, October 12, 2018 7:02 AM
    Wednesday, October 10, 2018 8:50 AM
    Moderator