How to Run Command Prompt Commands With a Desktop Shortcut
How to Open Command Prompt via Windows 10 Shortcut
To start, let’s explore how to open the command prompt using a Windows 10 shortcut. It won’t do anything right away; you’ll still have to manually type in the command you want to do. However, what we’ll cover here will act as the basis for the other commands we’ll cover in this article.
First, we need to create a CMD shortcut. To do this, right-click in an empty space in File Explorer or the desktop. Then, go to New > Shortcut.
When you click this, Windows 10 will immediately show a pop-up window asking for a location. In this window, type "C:\Windows\System32\cmd.exe" then click Next.
This is telling Windows to go into the system files and run the Command Prompt executable. If your Windows 10 installation is on another drive, replace the “C:\” with the drive you use for your OS.
Once you click Next, you can name the shortcut something memorable. Give it a name like “Open Command Prompt” and click Finish.
Now when you double-click your new shortcut, the command prompt appears.
How to Run a Command via Windows 10 Shortcut
Now that we’ve got the basics down, let’s learn how to make a CMD shortcut with a command built into it. If you want to make a new shortcut, repeat the steps above; however, if you want to edit the command you created previously, simply right-click it, click Properties, then add your new command under Target.
Now, let’s run a command via our shortcut. To do this, type "C:\Windows\System32\cmd.exe" /k followed by your command.
For example, "C:\Windows\System32\cmd.exe" /k echo hello world will tell the command prompt to print “hello world.”
You may notice the odd “/k” in the middle of the command. This tells the command prompt to run what we type after it, then stay open so that you can see the result.
If you prefer the command prompt to close as soon as it’s done, replace this /k with /c instead.
How to Run Multiple Commands via Windows 10 Shortcut
You can also chain multiple commands together. Just add an ampersand (&) between each command to chain them.
For example, "C:\Windows\System32\cmd.exe" /k echo hello & echo world will print “hello,” then “world.” You don’t need to repeat the /k or /c for each command; one at the start will do.
Examples of Useful Commands to Have As Shortcuts
Now you have everything you need to run commands from a shortcut, whether you want to manually type the command or automatically run a pre-set one. As such, let’s take some time to explore some useful ways you can use this tool to make specific tasks easier.
Ping or Trace the Route of a Specific Website or IP
If a website you visit goes down often, or you want to check the health of a remote server, the ping and tracert commands come in great use. Ping lets you see how fast your connection between you and the target is, while tracert lets you see each step in the connection.
To set up an automatic ping command, enter "C:\Windows\System32\cmd.exe" /k ping followed by your target.
For example, "C:\Windows\System32\cmd.exe" /k ping www.google.com will let you know how fast you can contact Google in milliseconds.
Flush the DNS Cache to Resolve Connection Issues
If you keep having DNS connection issues, why not set up an automatic shortcut that flushes your DNS cache? Just create a shortcut with "C:\Windows\System32\cmd.exe" /k ipconfig /flushdns and double-click it every time a DNS connection problem appears. You may even want to use /c for this command to close it once it’s finished.
Log Off, Restart, or Shut Down Your Computer
Finally, did you know that you can log off, restart, and turn off your PC from the command prompt? They all use the same “shutdown” command, but the variables you give the command defines which action you wish to perform.
All of the following commands are activated with "C:\Windows\System32\cmd.exe" /k shutdown, so enter that regardless of what you want to do. Then, add one of the following arguments to the end:
- /l will log off the current user.
- /r will restart the computer.
- /r /o will restart the computer then boot back into the advanced startup options.
- /s will turn off the computer.
- /s /hybrid shuts down the PC, then prepares it for a fast startup.
- /h will put the computer into hibernation mode.
- /a cancels a current shutdown sequence, as long as it’s done during the time out period.
- /t, when placed after a shutdown (/s) or restart (/r) command, defines how many seconds the PC will wait before performing that activity. Add a number after the /t to define the time; for example, /r /t 100 will restart the PC after 100 seconds pass.