Command line code to pin program to taskbar Windows 10?
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.
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"