How to automatically close cmd window after batch file execution?

后端 未结 8 1646
半阙折子戏
半阙折子戏 2020-11-30 23:47

I\'m running a batch file that has these two lines:

start C:\\Users\\Yiwei\\Downloads\\putty.exe -load \"MathCS-labMachine1\"
\"C:\\Program Files (x86)\\Xmi         


        
8条回答
  •  余生分开走
    2020-12-01 00:26

    You could try the somewhat dangerous: taskkill /IM cmd.exe ..dangerous bcz that will kill the cmd that is open and any cmd's opened before it.

    Or add a verification to confirm that you had the right cmd.exe and then kill it via PID, such as this:

    set loc=%time%%random%
    title=%loc%
    for /f "tokens=2 delims= " %%A in ('tasklist /v ^| findstr /i "%loc%"') do (taskkill /PID %%A) 
    

    Substitute (pslist &&A) or (tasklist /FI "PID eq %%A") for the (taskkill /PID %%A) if you want to check it first (and maybe have pstools installed).

提交回复
热议问题