How to Run Command Prompt Commands With a Desktop Shortcut
Opening the command prompt and typing in a command manually can get tiresome, but what if you could create a desktop shortcut to run commands whenever you please? Fortunately, while it’s not immediately obvious how to do this, it is possible in Windows 10 to create a command prompt shortcut.
Let’s explore how to make a Windows shortcut that runs a command prompt.
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.
"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.
"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.
"C:\Windows\System32\cmd.exe" /k ping www.google.com will let you know how fast you can contact Google in milliseconds.
"C:\Windows\System32\cmd.exe" /k tracert followed by your target will show you every step taken between you and the server. Using this on Google will show you all the servers your connection visits before it reaches the website.
If you’d like to know more about these commands, be sure to read up on the wireless network commands in Windows.
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.
Are you unsure as to what flushing the DNS cache actually does? Then be sure to read about what DNS is, and why it can become unavailable.
Check Your File System’s Health With Chkdsk and SFC
If you want to quickly check how your file system is doing, you can do so using Checkdisk (chkdsk) and the System File Checker (SFC). Chkdsk scans your entire computer for errors, while SFC does the same for just your important system files.
If you want easy access to these tools, you can create a checkdisk shortcut with
"C:\Windows\System32\cmd.exe" CHKDSK /f C: , and an SFC command with
"C:\Windows\System32\cmd.exe" /k sfc /scannow.
We covered both chkdsk and SFC in our guide on how to fix an unmountable boot drive, so be sure to check it out if you want to learn more about these commands.
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.
Using the Command Prompt in a Smarter Way
Constantly re-typing commands can get tiresome, so why not create a shortcut that does the hard work for you? Now you know how to make a shortcut that, when double-clicked, will either open the command prompt or automatically execute a command of your choosing.
If you want to know what kind of commands you can use with your new trick, why not check out the CMD prompts every Windows user must know?
Read the full article: How to Run Command Prompt Commands With a Desktop Shortcut