how to kill all batch files except the one currently running

前端 未结 3 1311
余生分开走
余生分开走 2020-12-18 10:23

How can you run a batch file which taskkills all other cmd.exes which are currently running, except for the one that is doing the task kill command?

3条回答
  •  心在旅途
    2020-12-18 11:09

    This worked for me, added to the very beginning of the .bat which is to kill all previously launched instances of itself, then immediately make itself susceptible to be killed by subsequent calls of the same .bat file:

    title NewlyLaunchedThing
    taskkill /F /IM cmd.exe /FI "WINDOWTITLE ne NewlyLaunchedThing"
    title Thing
    
    ...do everything else
    

    Note that, apparently, the "title" is a keyword, which sets a variable named "WINDOWTITLE".

    Also, the "=" (equals sign) is apparently optional for assigning title/WINDOWTITLE. Meaning, this works as well, and may be preferred for clarity:

    title = newTitle
    

提交回复
热议问题