How to find out if a batch file was opened by double click, or by command line
batch-file, cmd, windows
Solution
`%cmdcmdline%` gives the exact command line used to start the current Cmd.exe.
When launched from a command console, this var is `"%SystemRoot%\system32\cmd.exe"`.
When launched from explorer (double clicked) this var is `cmd /c ""{full_path_to_the_bat_file}"`
Problem
On a Windows 7, I have an executable, say `immutableProg.exe`, which I want to call 3 times with certain parameters. This is done by the batch file `myBatch.bat`. Content of `myBatch.bat`: ``` immutableProg.exe -a immutableProg.exe -b immutableProg.exe -c ``` The executable `immutableProg.exe` does have a special `--keep` switch which stops the executable from returning until a user hits any key. Now I want to add the `--keep` switch if and only if my batch `myBatch.bat` got double clicked like: ``` immutableProg.exe -a immutableProg.exe -b immutableProg.exe -c --keep ``` It shall NOT be added if a user calls the batch from commandline. The question: How can I find out (from inside my batch's view) if it was opened by a double click or from command line? Changing the default behavior of the `immutableProg.exe` is unfortunatelly not an option, neither is to give the batch file an extra parameter from commandline.