This guide shows you how to create a Windows shortcut that opens a command prompt where you can type a value, and then runs a command or program using that input. This is useful for launching scripts with custom parameters, quickly opening files or folders you specify, or running commands that need a variable each time. You’ll need a Windows PC and basic familiarity with creating shortcuts.
What You’ll Need
- A Windows computer (Windows 10 or 11)
- Knowledge of the command or program you want to run with the input
- Basic understanding of the Command Prompt (cmd.exe) syntax
Step-by-Step
- Right-click on your desktop (or in any folder), hover over New, and select Shortcut. This opens the Create Shortcut wizard.
- In the location field, enter the following command, replacing
YOUR_COMMANDwith the actual command or program you want to run. The key is usingset /pto capture the user’s input into a variable, then using that variable with thecallcommand. - Use this exact syntax:
cmd /k "set /p myvar=Enter your value: && call YOUR_COMMAND %myvar%"
For example, if you want to open a file whose name you type, replaceYOUR_COMMANDwithnotepad:cmd /k "set /p myvar=Enter filename: && call notepad %myvar%" - Click Next, give the shortcut a name like “Run with Input”, and click Finish. The shortcut is created.
- Test it by double-clicking the shortcut. A command prompt window will appear with the message “Enter your value:”. Type something (for example, a filename like
test.txt) and press Enter. The command should run with that input. - To make the window close after the command finishes, change
/kto/cin the command./kkeeps the window open,/ccloses it after execution. - If your command has multiple arguments, you can ask for multiple inputs. Use multiple
set /pstatements separated by&&and reference all variables:cmd /k "set /p var1=Enter first: && set /p var2=Enter second: && call YOUR_COMMAND %var1% %var2%" - To run a batch file that uses the input, you can call the batch file with the variable as an argument. For example, if you have a script
myscript.batthat expects a parameter, use:cmd /k "set /p myvar=Enter value: && call myscript.bat %myvar%" - For paths with spaces, you must enclose the variable in quotes. Change
%myvar%to"%myvar%"in the command. For example:cmd /k "set /p myvar=Enter path: && call notepad "%myvar%""(note the escaped quotes). - To set a default value if the user just presses Enter, you can use the
if definedcheck. This is more advanced but possible:cmd /k "set /p myvar=Enter value (default=test): && if not defined myvar set myvar=test && call YOUR_COMMAND %myvar%"
Common Mistakes
- Forgetting the
callcommand – Withoutcall, the command may not execute properly, especially if it’s a batch file. Always usecallbefore the command. - Missing the
&&between commands – Theset /pandcallmust be chained with&&so the command runs only after input is entered. - Not quoting paths with spaces – If the input contains spaces, you need to wrap the variable in quotes, otherwise the command will fail.
- Using
/kwhen you want the window to close – If you don’t want the prompt to stay open, use/c. - Escaping quotes incorrectly – In the shortcut location, quotes inside the command need to be escaped with a backslash, or the shortcut may not parse correctly.
Tips
- Test with a simple command first like
echoto verify the input is captured:cmd /k "set /p myvar=Enter: && call echo You typed %myvar%" - Use
%*in batch files if you want to pass all arguments at once, but this guide focuses on a single editable input. - You can pin the shortcut to the taskbar or Start menu for quick access.
- For more complex prompts, consider creating a small batch file that uses
set /pand then call that batch file from the shortcut. This makes editing easier. - If the command is a GUI program, the prompt window will stay open until you close the program. Use
startto launch it in a separate window if needed.
Troubleshooting
- The prompt window opens but closes immediately – This usually means the command failed. Add
pauseat the end of the command to see the error message. For example:cmd /k "set /p myvar=Enter: && call YOUR_COMMAND %myvar% && pause" - The input is not passed correctly – Ensure you have the
&&betweenset /pandcall, and that the variable name matches. Also check that you are using%myvar%(with percent signs) in the command. - Spaces in the input break the command – Quote the variable:
call YOUR_COMMAND "%myvar%". - The shortcut location is too long – Windows has a limit on shortcut target length (around 260 characters). If your command is long, create a batch file and call it instead.
- Antivirus or SmartScreen blocks the shortcut – If the command is unusual, Windows may warn. You can allow it by clicking “More info” and “Run anyway” when prompted.
- The variable is empty after pressing Enter – This is normal if the user just presses Enter. Use the
if not definedtrick to set a default.
Frequently Asked Questions
Can I use this to run a PowerShell command?
Yes, but the syntax changes. You would use powershell -Command with Read-Host instead of set /p. For example: powershell -Command "$var = Read-Host 'Enter value'; YOUR_COMMAND $var"
How do I make the prompt window open minimized?
Right-click the shortcut, select Properties, and in the Shortcut tab, change the Run dropdown to “Minimized”.
Can I have a drop-down list of options instead of free text?
Not with a simple shortcut. You would need to create a batch file that uses choice command or a PowerShell script with a GUI. This guide focuses on editable text input.
Why does my command not see the variable when I use it in a batch file?
Make sure you are passing the variable as an argument: call mybatch.bat %myvar%, and inside the batch file use %1 to access it. If you want to use the variable directly, you need to set it in the same session.
Can I use this to run a program as administrator?
Yes, right-click the shortcut, select Properties, click Advanced, and check “Run as administrator”. The prompt will appear after the UAC prompt.
Is there a way to save the input for later use?
You can redirect the input to a file within the command. For example, add echo %myvar% > input.txt after the call. But this is not built-in.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Gmail Gemini Privacy: Data Access & Limit Settings
- Fix Outlook Inbox Corruption with DISM in Windows
- How to Set Up Apple Pay on iPhone
- How to Choose a Refurbished iPhone With Years of Support
- NBA 2K Error Code: Fixes for Common Online Issues
- Voice Dictation in Google Docs: How to Use It