How can I tell whether a batch file was run from a command window?

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?


I tried Gene's suggestion on Windows 10:

if /I Not "%CMDCMDLINE:"=%" == "%COMSPEC% " Pause

But that didn't work for me. HOWEVER, when I removed the space at the end of %COMSPEC%, it did work:

if /I Not "%CMDCMDLINE:"=%" == "%COMSPEC%" Pause

I don't have the reputation to just comment on the original post, but would prefer someone add this to Gene's answer and upvote his (since he gave me the basis by which to solve my problem).