I have a batch file that I'd like to be able to be run by double-clicking on the file in Windows Explorer. When this is done, I want to end with a PAUSE so the window doesn't immediately close.
But if the batch file is run from a command shell, I'd prefer to not end with a PAUSE.
Is there some way to tell, within a batch file, whether it is running in a command-line spawned from Windows Explorer, or from an existing command shell?
Bash provides the special $- environment variable.
Is there something similar in cmd.exe?
Answer
Not an exact solution, but you can create a shortcut to your cmd file and add a command-line parameter to the target. When you need to run your cmd from Explorer, you will have to start she shortcut, not the cmd file.
In your cmd file you will test %1 parameter to identify whether it started from shortcut (from explorer) or from command prompt.
No comments:
Post a Comment