If you need to run command prompt commands regularly in Windows, it may be useful to save the command somehow so that you can run it whenever the need arises without having to type it all out again.
While you can use batch files for that, it is also possible to use shortcuts instead. The core difference between the two options is that you can only run a single command using shortcuts while you can run a series of commands and get better customization options when using batch files.
Adding commands as desktop shortcuts in Windows is a straightforward easy process that requires zero knowledge of batch files and little knowledge about the commands you want to run.
Basically, you are using the command %comspec% /k for that followed by the command that you want to run. For instance, if you wanted to display the contents of drive c you would use the command %comspec% /k dir c: for that.
Comspec is a system variable that defines the command interpreter used on the system. If you have not modified that, cmd.exe is being used. The k parameter of cmd.exe keeps the execution window open after running the command. If you don't require that, you may replace it with /c which terminates it.
Adding the shortcut
To add a new shortcut, right-click on a blank spot on your desktop and select New > Shortcut from the context menu.
Type the command that you want executed whenever you run the shortcut, for instance %comspec% /k dir c: or any other command in that format.
Click the next button and name the shortcut. The default name is set to cmd.exe which you may want to change, especially if you want to add multiple command prompt shortcuts on the system.
Once done run the shortcut to verify that it is working correctly. It is easiest with the /k parameter as you see the output in the command prompt window. Once you have verified the correctness, you may remove the /k parameter if you don't need to see the output on the screen.
Using shortcuts to run commands on the command prompt can be quite useful, for instance if you need to run a command regularly. This can be something simple as the directory command listed above but also advanced commands that turn features on or off for example.
Now You: Have another tip? Feel free to share it with everyone else in the comment section below.
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.