How to run command prompt commands from desktop shortcuts in Windows
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.
Despite the fact that yes you can run commands as a shortcut (which is really all shortcuts are) I think the route of going with a batch file or vbs script for generic tools is probably the more economically and desktop friendly way of approaching it. Decreases clutter and can run a series of commands in succession. Single command though wouldn’t hurt.
shutdown /f /s /t 0
Probably one of my more used commands on anything greater than Windows XP, when the option of shutdown includes “install updates”, that’s a quick bypass. So yeah I can see a use for it, but would suggest batch more often.
WinKey+R > net stop wuauserv
Who wants to restart their computer after Windows Updates complete? Or get nagged to do so? I shut my computer down each day. It may be different for those who use the hibernate or standby options though.
WinKey+R > %temp%
(then delete all files older than 24 hours old)
It’s amazing how many people don’t have Windows doing automatic maintenance, and their computer gets clogged up (and slowed down) with thousands of temporary files.
Hi What I have done is went to Windows system32 folder, right click cmd command send to desktop. Easy
I found out that recently that you can type in commands into Explorer’s path bar, it’s much faster than creating shortcuts, also command history is saved in the list revealed by Alt+Down. It works in Win 7 and 8, in XP it’s a bit different and not always require you to type cmd.exe before the command itself.
The solutions turned out to be very simple.
1. Open text edit
2. Write the command, save
3. Double click the file created and the command automatically starts running in command-prompt.