Solved
Forum Discussion
Lindaaq
4 years agoNew Member
It would be good if there is a way to detect if a .cmd file was started by doubleclick in the explorer or if it was started by a already open command line. In the later case (and especially if executed by another program) you dont want the pause
- AlexKaras4 years ago
Champion Level 2
Lindaaq :
Hi,
> if there is a way to detect if a .cmd file was started [...]
Check if this work for you:
REM Find out if this file was started interactively
REM %interactive%==0 if started not from cmd window (i.e., e.g. by double-clicking in Explorer)
set interactive=1
echo %cmdcmdline% | find /i "%~0" > nul
if not errorlevel 1 set interactive=0rem Execute required commands here
:End
if _%interactive%_==_0_ pause
exit /b %errorlevel%