Shortcut that opens a command prompt and runs an application

command lineshortcuts

I know how to make a shortcut to cmd.exe and set the start-location to my target directory. But I would like the shortcut to run an application in the console window… basically my application run with no commands will print a welcome message, instructing the user how to launch it. he user then interacts with this command-prompt as normal.

So I want a shortcut that will:

  • open the command prompt ina given folder
  • run a specified program in that folder
  • keep the command prompt open afterwards for me to interact with

Is this possible?

Best Answer

You can use this:

cmd.exe /k "cd /d "Filepath" & start program.exe"
  • /k switch tells to keep command prompt open after command execution.
  • cd changes directory to the file path, /d switch makes it safer because without this switch over-drive paths cannot be changed.
  • Then start the program.

You can create a shortcut. Right click on desktop > New > Shortcut. Then put the code there and give it a name. You can also put it in a batch file.

By the way

Inspired by @spikey_richie idea:

@echo off & cd /d "Filepath" & start program.exe & pause >nul

If you don't want to keep command prompt open, but wait termination or a key press.