Windows

How to Run Command Prompt Commands With a Desktop Shortcut

Simon Batt Updated 02-07-2020

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.

Advertisement

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.

Creating a 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.

Advertisement

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.

Defining a path for the shortcut

Once you click Next, you can name the shortcut something memorable. Give it a name like “Open Command Prompt” and click Finish.

Naming a new shortcut

Advertisement

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.

Changing the path of a shortcut

Now, let’s run a command via our shortcut. To do this, type "C:\Windows\System32\cmd.exe" /k followed by your command.

Advertisement

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.

Advertisement

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.

Likewise, using "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 8 CMD Commands to Manage Wireless Networks in Windows Use the Command Prompt to control your Wi-Fi network. Here are the most useful commands for troubleshooting your home network. Read More .

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 What Is a DNS Server and Why Is It Unavailable? A DNS server matches a host and domain name with its server IP address. When a DNS server is unavailable, you can't reach the URL. Read More .

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 How to Fix an Unmountable Boot Volume in Windows 10 Seeing the "unmountable boot volume" stop code in Windows 10? Here's how to troubleshoot an unmountable boot volume. Read More , 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? And have you had a look at the new Windows Terminal How to Use the New Windows Terminal for Your Productivity The way you type commands might change with the launch of the Windows Terminal. Let's explore some of its attractive features. Read More , yet?

Related topics: Command Prompt, Windows Tips, Windows Tricks.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Harv
    August 3, 2020 at 11:37 am

    Hi,
    When creating the shortcut, the quote marks are not retained,
    "C:\Windows\System32\cmd.exe"
    Therefore unable to run my netsh command: netsh wlan show wlanreport
    Suggestions?
    Windows 1909 Build 18363.959

  2. Rodolfo Rodriguez
    July 6, 2020 at 8:09 pm

    I think it’s better to create a Batch file when running multiple commands.

    • Thomas Aussenegg
      July 17, 2020 at 5:36 pm

      I recommend REXX for cmd execution programming.
      The language is elegant and powerful and runs on
      practically all possible hardware platforms.

  3. Tul
    March 1, 2019 at 4:14 pm

    Thank you for a great, super simple and direct article, with no superlative bs. Thanks

  4. quadstrike
    October 18, 2016 at 4:19 am

    or just make a bat file

  5. John Merc
    October 6, 2016 at 7:47 am

    Nice and Helpful article.
    However I want to know where is login link in this new website?
    And what about my saved articles?

    Thanks in advance.

  6. ultimate tech news
    October 5, 2016 at 12:45 pm

    wow great article