PDF download Download Article PDF download Download Article

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”.

Method 1
Method 1 of 2:

Creating a Desktop Shortcut

PDF download Download Article
  1. Advertisement
    • 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.
  2. Whatever command you type after %comspec% /k is the one that will run when you double-click this shortcut. For example:[1]
    • %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.
  3. This is the text that will appear under the icon.
    • For example, if the shortcut pings Google, you could type ping google.
  4. The shortcut is now on your desktop.
  5. The command prompt window will appear, and you’ll see your command running.
  6. Advertisement
Method 2
Method 2 of 2:

Creating a Keyboard Shortcut

PDF download Download Article
  1. 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.[2]
    • Keyboard shortcuts will follow the format Ctrl+Alt+[other key].
    • You’ll be able to choose a letter, number, or punctuation key as the “other key.” For example, b, ., 3.
  2. The “Shortcut” tab of the Properties screen will appear.
  3. The text box will fill with the entire shortcut using the key you press.
    • For example, if you press p, the text in the box will change to Ctrl + Alt + P.
    • If you create multiple keyboard shortcuts, make sure not to use the same key twice.[3]
  4. You’ll now return to the desktop.
  5. The command prompt window will appear, running the command you set up in the desktop shortcut.
  6. Advertisement

Community Q&A

Search
Add New Question
  • Question
    How do I make a shortcut for run command?
    Community Answer
    Community Answer
    You can pin command prompt to your taskbar. Just open cmd and right click, then press "Pin to taskbar."
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

  • Some apps have their own shortcuts (like Ctrl+Alt+I in Photoshop) that may match yours. Minimize open applications before using a keyboard shortcut so you don’t accidentally run it in an app.
  • You can drag a desktop shortcut to the Windows taskbar if you’d prefer it not be on the desktop.
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement

You Might Also Like

Create Your Own Run CommandCreate Your Own Run Command
Make a Shutdown Shortcut in Windows Create a Shutdown Shortcut on Your Windows Desktop or Taskbar
Open Command Prompt with a Keyboard Shortcut (Windows 8, 8.1, and 10)4 Ways to Open Command Prompt with Keyboard on Windows
Run a Program on Command Prompt Run a Program at the Windows Command Prompt: 2 Ways
Create a Desktop Shortcut Create Desktop Shortcuts for Files & Websites
Use Keyboard Shortcuts Use Keyboard Shortcuts Like a Pro: The Complete Guide
Add a Website Link to the Start MenuAdd a Website Link to the Start Menu
Open the Command Prompt in Windows6 Simple Ways to Open the Command Line in Windows
Add a Google Shortcut on Your Desktop Create a Desktop Shortcut for Google on Any Browser
Find All Commands of CMD in Your Computer Display and Use CMD Commands: A List and Guide
Run Task Manager from Command PromptRun Task Manager in CMD (+ More Task Manager Commands)
Shut Down Your PC with a Shortcut Key6 Easy Ways to Use Shortcut Keys to Shut Down a Windows PC
Open Terminal in Windows Open the Windows Terminal: A Quick Guide
Run Command Prompt As an Administrator on Windows4 Ways to Run the Command Prompt as an Administrator in Windows
Advertisement

About This Article

Nicole Levine, MFA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 36,553 times.
How helpful is this?
Co-authors: 3
Updated: October 7, 2025
Views: 36,553
Categories: Command Prompt
Thanks to all authors for creating a page that has been read 36,553 times.

Is this article up to date?

Advertisement