sodcalculator

10 Tech How-To

Windows Shortcut: Prompt With Editable Input

Guide 10-19192 · Updated · Step by step

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

  1. Right-click on your desktop (or in any folder), hover over New, and select Shortcut. This opens the Create Shortcut wizard.
  2. In the location field, enter the following command, replacing YOUR_COMMAND with the actual command or program you want to run. The key is using set /p to capture the user’s input into a variable, then using that variable with the call command.
  3. 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, replace YOUR_COMMAND with notepad:
    cmd /k "set /p myvar=Enter filename: && call notepad %myvar%"
  4. Click Next, give the shortcut a name like “Run with Input”, and click Finish. The shortcut is created.
  5. 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.
  6. To make the window close after the command finishes, change /k to /c in the command. /k keeps the window open, /c closes it after execution.
  7. If your command has multiple arguments, you can ask for multiple inputs. Use multiple set /p statements separated by && and reference all variables:
    cmd /k "set /p var1=Enter first: && set /p var2=Enter second: && call YOUR_COMMAND %var1% %var2%"
  8. 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.bat that expects a parameter, use:
    cmd /k "set /p myvar=Enter value: && call myscript.bat %myvar%"
  9. 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).
  10. To set a default value if the user just presses Enter, you can use the if defined check. 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 call command – Without call, the command may not execute properly, especially if it’s a batch file. Always use call before the command.
  • Missing the && between commands – The set /p and call must 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 /k when 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 echo to 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 /p and 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 start to launch it in a separate window if needed.

Troubleshooting

  • The prompt window opens but closes immediately – This usually means the command failed. Add pause at 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 && between set /p and call, 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 defined trick 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

The whole Tech How-To bed →