How to Run Command Prompt Commands from a Windows Shortcut

Right-click a blank area of the desktop., Click Shortcut. , Type %comspec% /k into the text box., Press the spacebar. , Type the command you want to run., Click Next. , Enter a name for the shortcut., Click Finish., Double-click the shortcut to run...

9 Steps 1 min read Medium

Step-by-Step Guide

  1. Step 1: Right-click a blank area of the desktop.

    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. ,, Whatever command you type after %comspec% /k is the one that will run when you double-click this shortcut.

    For example:%comspec% /k ping www.google.com will ping www.google.com when you double-click the shortcut. %comspec% /k sfc scannow will scan all protected system files when you double-click the shortcut. ,, This is the text that will appear under the icon.

    For example, if the shortcut pings Google, you could type ping google. , The shortcut is now on your desktop. , The command prompt window will appear, and you’ll see your command running.
  2. Step 2: Click Shortcut.

  3. Step 3: Type %comspec% /k into the text box.

  4. Step 4: Press the spacebar.

  5. Step 5: Type the command you want to run.

  6. Step 6: Click Next.

  7. Step 7: Enter a name for the shortcut.

  8. Step 8: Click Finish.

  9. Step 9: Double-click the shortcut to run the command.

Detailed Guide

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. ,, Whatever command you type after %comspec% /k is the one that will run when you double-click this shortcut.

For example:%comspec% /k ping www.google.com will ping www.google.com when you double-click the shortcut. %comspec% /k sfc scannow will scan all protected system files when you double-click the shortcut. ,, This is the text that will appear under the icon.

For example, if the shortcut pings Google, you could type ping google. , The shortcut is now on your desktop. , The command prompt window will appear, and you’ll see your command running.

About the Author

J

Jean Cooper

Enthusiastic about teaching practical skills techniques through clear, step-by-step guides.

91 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: