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.
The wikiHow Tech Team also followed the article's instructions and verified that they work.
This article has been viewed 24,292 times.
Learn more...
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”.
Steps
Creating a Desktop Shortcut
-
1Right-click a blank area of the desktop.[1]
-
2Click Shortcut.Advertisement
-
3Type %comspec% /k into the text box.
- 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.
-
4Press the spacebar.
-
5Type 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]
- %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.
-
6Click Next.
-
7Enter a name for the shortcut. This is the text that will appear under the icon.
- For example, if the shortcut pings Google, you could type ping google.
-
8Click Finish. The shortcut is now on your desktop.
-
9Double-click the shortcut to run the command. The command prompt window will appear, and you’ll see your command running.
Creating a Keyboard Shortcut
-
1Create 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]
- 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.
-
2Right-click the desktop shortcut.
-
3Click Properties. The “Shortcut” tab of the Properties screen will appear.
-
4Click into the “Shortcut Key” box.
-
5Press a letter, number, or punctuation key. 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.[4]
-
6Click OK. You’ll now return to the desktop.
-
7Press Ctrl+Alt+[other key] to run the command. The command prompt window will appear, running the command you set up in the desktop shortcut.
Community Q&A
-
QuestionHow do I make a shortcut for run command?Community AnswerYou can pin command prompt to your taskbar. Just open cmd and right click, then press "Pin to taskbar."
References
- ↑ http://www.ghacks.net/2015/06/05/how-to-run-command-prompt-commands-from-desktop-shortcuts-in-windows/
- ↑ https://technet.microsoft.com/en-us/library/bb490968.aspx
- ↑ http://www.laptopmag.com/articles/create-keyboard-shortcuts-windows-10
- ↑ http://www.laptopmag.com/articles/create-keyboard-shortcuts-windows-10