I have a bat file that does a bunch of things and closes the cmd window which is fine when user double clicks the bat file from explorer. But if I run the bat file from a al
Build upon the other answers, I find the most robust approach to:
x
to enable text comparison without breaking the IF statement.x
).set "dclickcmdx=%systemroot%\system32\cmd.exe /c xx%~0x x"
set "actualcmdx=%cmdcmdline:"=x%"
set isdoubleclicked=0
if /I "%dclickcmdx%" EQU "%actualcmdx%" (
set isdoubleclicked=1
)
This adds more robustness against general cmd /c
calls, since Explorer adds an awkward extra space before the last quote/x (in our favor). If cmdcmdline
isn't found, it correctly renders isdoubleclicked=0
.