One of my favorite features in Windows 7 is the taskbar, as it combines the convenience of Vista’s Quick Launch, while organizing windows in a more intuitive manner. I’ve grown accustomed to dragging program shortcuts into it, and having them remain there permanently. That is, until this morning. For some reason, I discovered that Windows wouldn’t let me drag a batch file to the taskbar.
In DOS, OS/2, and Microsoft Windows, batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter.
Even when I right-clicked the file, I didn’t see the typical “Pin to Taskbar” shortcut. Seeing as batch scripts can execute programs within themselves, I was surprised they were being blocked. After running a few web searches, I found a solution to the problem, and felt it would be worthwhile to share it here.
For the sake of this tutorial, let’s assume that we’re trying to pin a batch file titled “myscript.bat” to the taskbar. Since we can’t pin it directly, we’ll be using a trick that involves the Windows Command Prompt. Here’s how to do it:
- Click the Start button.
- Start typing “Command Prompt” in the search box.
- Right-click Command Prompt once it appears in the search results, and select Pin to Taskbar.
- While holding SHIFT, right-click the black Command Prompt icon in the taskbar.
- Select Properties from the context menu that appeared.
Now we bring our attention to the value in the Target field:
As it stands, it’s just trying to launch the executable that will make the Command Prompt window appear. For our trick to work, we must add the follow text, in bold:
%windir%\system32\cmd.exe /c “c:\somewhere\myscript.bat”
The “/c” parameter tells “cmd.exe” that it should only run the command provided, and then immediately close itself. In this case, we’re telling it to launch a batch file, and that file can run any number of commands within itself. The path, naturally, should reflect the actual location of the file on your machine.
Once this is set up, we can simply click the black Command Prompt icon to launch our script. I have no idea if Microsoft plans to improve support for such files, but in the meantime, I consider this a decent workaround.