How to Run Command Prompt Commands from a Windows Shortcut

To create a Windows shortcut that runs a command at the command prompt, right-click the desktop → select 'Shortcut' → Enter the command (prefaced by '|%comspec% /k' → Click 'Next' → Enter a name for the shortcut → click 'Finish'. Right-cli...

Method 1 of 2:

Creating a Desktop Shortcut

  1. Picture 1 of How to Run Command Prompt Commands from a Windows Shortcut
    Right-click a blank area of the desktop.[1]
  2. Picture 2 of How to Run Command Prompt Commands from a Windows Shortcut
    Click Shortcut.
  3. Picture 3 of How to Run Command Prompt Commands from a Windows Shortcut
    Type %comspec% /k into the text box.
    1. The -k flag keeps the command prompt window open after the command is run. You can remove the flag if you prefer the window closes right away.
  4. Picture 4 of How to Run Command Prompt Commands from a Windows Shortcut
    Press the spacebar.
  5. Picture 5 of How to Run Command Prompt Commands from a Windows Shortcut
    Type the command you want to run. Whatever command you type after %comspec% /k is the one that will run when you double-click this shortcut. For example:[2]
    1. %comspec% /k ping www.google.com will ping www.google.com when you double-click the shortcut.
    2. %comspec% /k sfc scannow will scan all protected system files when you double-click the shortcut.
  6. Picture 6 of How to Run Command Prompt Commands from a Windows Shortcut
    Click Next.
  7. Picture 7 of How to Run Command Prompt Commands from a Windows Shortcut
    Enter a name for the shortcut. This is the text that will appear under the icon.
    1. For example, if the shortcut pings Google, you could type ping google.
  8. Picture 8 of How to Run Command Prompt Commands from a Windows Shortcut
    Click Finish. The shortcut is now on your desktop.
  9. Picture 9 of How to Run Command Prompt Commands from a Windows Shortcut
    Double-click the shortcut to run the command. The command prompt window will appear, and you'll see your command running.
Method 2 of 2:

Creating a Keyboard Shortcut

  1. Picture 10 of How to Run Command Prompt Commands from a Windows Shortcut
    Create a desktop shortcut for the command. A keyboard shortcut is a combination of keyboard keys you press to run a command or program. To create one for a command line command, make sure you've already created a desktop shortcut.[3]
    1. Keyboard shortcuts will follow the format Ctrl+Alt+[other key].
    2. You'll be able to choose a letter, number, or punctuation key as the 'other key.' For example, b, ., 3.
  2. Picture 11 of How to Run Command Prompt Commands from a Windows Shortcut
    Right-click the desktop shortcut.
  3. Picture 12 of How to Run Command Prompt Commands from a Windows Shortcut
    Click Properties. The 'Shortcut' tab of the Properties screen will appear.
  4. Picture 13 of How to Run Command Prompt Commands from a Windows Shortcut
    Click into the 'Shortcut Key' box.
  5. Picture 14 of How to Run Command Prompt Commands from a Windows Shortcut
    Press a letter, number, or punctuation key. The text box will fill with the entire shortcut using the key you press.
    1. For example, if you press p, the text in the box will change to Ctrl + Alt + P.
    2. If you create multiple keyboard shortcuts, make sure not to use the same key twice.[4]
  6. Picture 15 of How to Run Command Prompt Commands from a Windows Shortcut
    Click OK. You'll now return to the desktop.
  7. Picture 16 of How to Run Command Prompt Commands from a Windows Shortcut
    Press Ctrl+Alt+[other key] to run the command. The command prompt window will appear, running the command you set up in the desktop shortcut.
Update 04 March 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile