18

I'm trying to reimage several computers, and am making a batch file to run the basic commands. Is there a command line code that will allow me to pin programs to the task bar? For instance, Internet Explorer.

0

6 Answers 6

11

Opinion - Microsoft explicity does not want to provide a method for anyone to add/remove pin items for the user. They are worried about third party applications arbitrarily pinning and unpinning items as a way to influence which programs a user will run. Therefore they have made this very difficult on the latest versions of Windows 10.

Method 1 - There WAS a method for scripting this using VBScript which involved enumerating through FolderItem.Verbs and activating the one called "pin to taskbar". However Microsoft removed this item from the Verbs collection while leaving it available on the UI for manual selection with a mouse. There are many websites that explain exactly how to do this with a VB script but this method does not work on the latest versions of Windows 10.

Method 2 - Probably due to backlash from the enterprise community, Microsoft now provides a method through the use of Group Policy to create a default set of items to unpin or pin for a new user account but this does not appear to be useful for one-off customized pinning. An internet search for the following terms will lead to the info: group policy taskbar pin.

Method 3 - The other answer provided here, simply copying a link file to the User Pinned\Taskbar folder, WILL NOT WORK in current versions of Windows 10. It may have worked at some point but this does not work any longer.

Method 4 - There is a third party utility called SYSPIN. This is a standalone EXE that apparently works. The company or website is called TECHNOSYS.

6

You need to create a shortcut and then move that shortcut into the user pinned folder.

UserPinned folder is here: %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

Here, we will create a notepad shortcut (notepad.lnk) and move it to the user pinned folder.

The only things that need to be changed for your applications are:

sLinkFile=Name of your shortcut (application_Name.lnk usually)

oLink.TargetPath= Path of your root application (c:\program files\program\program.exe)

@echo off
echo Set oWS = WScript.CreateObject("WScript.Shell") > C:\temp8\CreateShortcut.vbs
echo sLinkFile = "C:\temp8\notepad.lnk" >> C:\temp8\CreateShortcut.vbs
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> C:\temp8\CreateShortcut.vbs
echo oLink.TargetPath = "C:\Windows\notepad.exe" >> C:\temp8\CreateShortcut.vbs
echo oLink.Save >> C:\temp8\CreateShortcut.vbs
cscript C:\temp8\CreateShortcut.vbs
del C:\temp8\CreateShortcut.vbs
copy "C:\temp8\notepad.lnk" "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\notepad.lnk"
pause

You can remove pause, I just had it for error checking. Copy the code above into your bat file.

Edit: In depth explanation:

Essentially the > and the >> symbols append data to a document. In this case, we are creating a separate .vbs file called CreateShortcut.vbs and each command before the > or >> is getting put into that file, line by line. At the end of the batch, we run cscript CreateShort.vbs which executes the file that we just built.

@echo off

REM Create a new obj for shell script and write as line 1 in new file call createshortcut.vbs
    echo Set oWS = WScript.CreateObject("WScript.Shell") > C:\temp8\CreateShortcut.vbs

REM Name the shortcut whatever you want. It will end in .lnk and then write that command as the second line in the createshortcut.vbs file
    echo sLinkFile = "C:\temp8\notepad.lnk" >> C:\temp8\CreateShortcut.vbs

REM takes the shortcut file and runs the builtin script "create Shortcut to generate the .lnk file and adds as the third line in the createshortcut.vbs file
    echo Set oLink = oWS.CreateShortcut(sLinkFile) >> C:\temp8\CreateShortcut.vbs

REM this is physical path of the EXE or application you are making a shortcut for, then adds that path as the 4th line in the createshortcut.vbs file
    echo oLink.TargetPath = "C:\Windows\notepad.exe" >> C:\temp8\CreateShortcut.vbs

REM saves everything and writes as the 5th line in the vbs file
    echo oLink.Save >> C:\temp8\CreateShortcut.vbs

REM executes the createshortcut.vbs file that we built line by line above
    cscript C:\temp8\CreateShortcut.vbs

REM Deletes the createshortcut.vbs script that we made after it ran so you can use this block of code in the same batch more than once
    del C:\temp8\CreateShortcut.vbs

REM Copies the newly created shortcut file notepad.lnk to the directory that windows looks at to generate what icons/applications appear on the taskbar
    copy "C:\temp8\notepad.lnk" "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\notepad.lnk"
1
  • 6
    Terminal Server 2016: In the ...\User Pinned\TaskBar folder I see the short cuts which are also displayed in the taskbar. But adding or removing shortcuts from that folder does not affect the icons in the taskbar (even after a logon / logoff user session) Jul 11, 2018 at 13:01
3

I just found a very simple solution here.

Just create the shortcut to the script file, then go to its properties, and change target from "C:\path-to-your-batch" to cmd.exe /C "path-to-your-batch".

After that, the icon of the shortcut changes and you can drop it on the taskbar to pin it.

2

You don't say if using an external program is acceptable for you. You can use pttb, here https://github.com/0x546F6D/pttb_-_Pin_To_TaskBar

Example: pttb c:\Windows\system32\notepad.exe

0

You can pin programs with the Taskbar folder but you have to change a registry key as well.

What I did was on one computer, I pinned the programs I need for the local admin account. I then ran the following commands:

robocopy "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" C:\Temp\Taskbar

reg export HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband C:\Temp\Taskbar.reg

Since the computers are on a domain I was able to run these commands from another computer with domain admin rights:

robocopy \\SourcePC\C$\Temp\Taskbar \\DestinationPC\C$\Temp\Taskbar

robocopy \\SourcePC\C$\Temp \\DestinationPC\C$\Temp Taskbar.reg

From the destination PC make sure you back up the current registry key just in case!!!

reg export HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband C:\Temp\Taskbar-Backup.reg

robocopy C:\Temp\Taskbar "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"

reg import C:\Temp\Taskbar.reg

Log off and log back in and the icons should be pinned to your taskbar.

0

Refer to this answer that i tweaked for my aim, you can try this vbscript in order to pin a program to taskbar using Vbscript in Windows 10.

Vbscript : TaskBarPin.vbs

Option Explicit
REM Question Asked here ==> 
REM https://stackoverflow.com/questions/31720595/pin-program-to-taskbar-using-ps-in-windows-10/34182076#34182076
Dim Title,objFSO,ws,objFile,sKey1,sKey2,KeyValue
Title = "Pin a program to taskbar using Vbscript in Windows 10"
'----------------------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Ws     = CreateObject("WScript.Shell")
objFile    = DeQuote(InputBox("Type the whole path of the program to be pinned or unpinned !",Title,_
"%ProgramFiles%\windows nt\accessories\wordpad.exe"))
REM Examples
REM "%ProgramFiles%\Mozilla Firefox\firefox.exe"
REM "%ProgramFiles%\Google\Chrome\Application\chrome.exe"
REM "%ProgramFiles%\windows nt\accessories\wordpad.exe"
REM "%Windir%\Notepad.exe"
ObjFile = ws.ExpandEnvironmentStrings(ObjFile)
If ObjFile = "" Then Wscript.Quit()
sKey1      = "HKCU\Software\Classes\*\shell\{:}\\"
sKey2      = Replace(sKey1, "\\", "\ExplorerCommandHandler")
'----------------------------------------------------------------------
With CreateObject("WScript.Shell")
    KeyValue = .RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" & _
    "\CommandStore\shell\Windows.taskbarpin\ExplorerCommandHandler")
    .RegWrite sKey2, KeyValue, "REG_SZ"
    
    With CreateObject("Shell.Application")
        With .Namespace(objFSO.GetParentFolderName(objFile))
            With .ParseName(objFSO.GetFileName(objFile))
                .InvokeVerb("{:}")
            End With
            
        End With
    End With
    .Run("Reg.exe delete """ & Replace(sKey1, "\\", "") & """ /F"), 0, True
End With
'----------------------------------------------------------------------
Function DeQuote(S)
    If Left(S,1) = """" And Right(S, 1) = """" Then 
        DeQuote = Trim(Mid(S, 2, Len(S) - 2))
    Else 
        DeQuote = Trim(S)
    End If
End Function
'----------------------------------------------------------------------

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .