Detect if bat file is running via double click or from cmd window

前端 未结 12 1722
醉话见心
醉话见心 2020-12-29 02:54

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

12条回答
  •  滥情空心
    2020-12-29 03:18

    Like @anishsane I too wanted a pause statement if launched from explorer, but not when launched from a command window.

    Here's what worked for me, based upon @mousio's answer above:

    @SET cmdcmdline|FINDSTR /b "cmdcmdline="|FINDSTR /i pushd >nul
    @IF ERRORLEVEL 1 (
        @echo.
        @echo Press ENTER when done
        @pause > nul
    )
    

    (Nothing original here, just providing a working example)

提交回复
热议问题