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
-
How to Run Command Prompt Commands from a Windows Shortcut Picture 1
Right-click a blank area of the desktop.[1] -
How to Run Command Prompt Commands from a Windows Shortcut Picture 2
Click Shortcut. -
How to Run Command Prompt Commands from a Windows Shortcut Picture 3
Type %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.
-
How to Run Command Prompt Commands from a Windows Shortcut Picture 4
Press the spacebar. -
How to Run Command Prompt Commands from a Windows Shortcut Picture 5
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]- %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.
-
How to Run Command Prompt Commands from a Windows Shortcut Picture 6
Click Next. -
How to Run Command Prompt Commands from a Windows Shortcut Picture 7
Enter 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.
-
How to Run Command Prompt Commands from a Windows Shortcut Picture 8
Click Finish. The shortcut is now on your desktop. -
How to Run Command Prompt Commands from a Windows Shortcut Picture 9
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
-
How to Run Command Prompt Commands from a Windows Shortcut Picture 10
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]- 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.
-
How to Run Command Prompt Commands from a Windows Shortcut Picture 11
Right-click the desktop shortcut. -
How to Run Command Prompt Commands from a Windows Shortcut Picture 12
Click Properties. The 'Shortcut' tab of the Properties screen will appear. -
How to Run Command Prompt Commands from a Windows Shortcut Picture 13
Click into the 'Shortcut Key' box. -
How to Run Command Prompt Commands from a Windows Shortcut Picture 14
Press 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]
-
How to Run Command Prompt Commands from a Windows Shortcut Picture 15
Click OK. You'll now return to the desktop. -
How to Run Command Prompt Commands from a Windows Shortcut Picture 16
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.
4.3 ★ | 4 Vote
You should read it
- How to Quickly Show the Desktop on a Mac
- How to Create a Desktop Shortcut
- How to create VPN shortcut on Windows 10 desktop
- How to change the default shortcut in Windows 10
- How to Set a Keyboard Shortcut to Open Spotlight
- The shortcut virus removal has never been this simple
- How to Put a Shortcut to a Website on Your Desktop
- How to Create Desktop Shortcuts for Office Programs on PC or Mac
- How to use the command history function in Command Prompt
- How to Make the Show Desktop Icon in Windows Quick Launch Toolbar
- Quickly launch applications on the desktop with a shortcut
- How to Make a Shutdown Shortcut in Windows