Any person who has to run command prompt commands very often in Windows can make use of shortcuts for them. Typing out the command prompt commands frequently becomes cumbersome. You begin to wonder if you could use some alternate methods to avoid this repeated typing by saving the command prompt commands and running it whenever you want. That is when shortcuts come into the picture.
What are Windows Desktop Shortcuts?
Windows desktop shortcuts provide you with an option to access executable files, folders, and applications quickly. You can also use the desktop shortcuts to run command prompt commands.
Difference Between Using Batch Files and Windows Desktop Shortcuts
Batch files can be used for running a series of command prompt commands with customization options. On the contrary, if you want to run a single or a simple command, then using Windows shortcuts is the best option and setting up a shortcut to run command prompt commands makes it even easier.
Steps to Create a Windows Shortcut to Run Command Prompt Commands
- To create a new shortcut to run command prompt commands on your desktop, right-click anywhere in the blank region on your desktop. Now, select the option New > Shortcut from the context menu.
- In the “New Shortcut” window, type the command that should be executed whenever the shortcut is run using the syntax as follows:
“C:\Windows\System32\cmd.exe” /k requiredcommand
Let us see what this command indicates:
- Here, the initial part “cmd.exe” indicates that the command prompt must be opened.
- The second part, /k is a flag that instructs the command prompt to issue the following command and remain open in order to see the results or type other commands. If you want the command prompt to close after the command is issued, the flag “/c” can be used instead of “/k”.
- The final part, “requiredcommand” is the actual command that you wish to execute or run.
- Click on the Next button.
- Type a suitable name for the shortcut and click on the Finish button.
That’s all. It is now possible for you to run command prompt commands from a shortcut easily by just double clicking on it instead of typing the command in the command prompt.
Redirecting Results to a File Through Shortcuts
You can also redirect the results of any command prompt command to another program file and then ensure that the command prompt window closes. For this you must use symbols like > and >>. For example, if you run the “requiredcommand” command and want to save the results in a file called abc.txt and then close the command prompt windows the following syntax can be used.
“C:\Windows\System32\cmd.exe” /c requiredcommand > “C:\Users\Default\Desktop\ abc.txt
If > is used, then Windows will create a new file if it does not exist. If the file exists, it will overwrite the contents of the file. If you do not want to overwrite the contents of the file, but just append the new results of the command to the existing data in the file, you must use the >> command.
Once the shortcut for redirecting results is ready, you can run the command any time you want by using the shortcuts. Thus, you can easily run command prompt commands from a Windows shortcut and save yourself a lot of typing.