0

When you create a windows commandline application, is there a way to detect whether it was run from explorer by double clicking or by typing the command into a pre-existing shell window?

The usecase:

A terminal application expects some user input, and once this was provided, prints an error message and exits.

This is OK, if the CMD-Window was previously opened, and the command started in that shell, the User will be able to read that error message. However, if the user just double-clicked the .exe in Explorer, the Dosbox will open, expect the user input, and once that was provided print the errormessage, and instantly close that dosbox again, so the user has no chance to read the error message.

This could also hit you if you try to launch the application in the Visual Studio Debugger.

I want to detect this case, and instead wait for another key press to exit the application after the user was given a chance to read the actual error message.

dothebart
  • 5,972
  • 16
  • 40
  • 1
    https://stackoverflow.com/a/13256385/17034 – Hans Passant Mar 27 '19 at 12:54
  • thanks, I only found https://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script and https://devblogs.microsoft.com/commandline/how-to-determine-what-just-ran-on-windows-console/ by googling, which weren't helpfull... – dothebart Mar 27 '19 at 16:05
  • 1
    I think ``GetConsoleProcessList`` function would help, as answered by Hans on the provided link. – Ajay Mar 28 '19 at 07:36

0 Answers0