Search code examples
batch-filessmsforceclose

Stop execution of SQL query and kill ssms from a .bat file


Yesterday I did something bad. I left a SQL query running to see how long it would take, then promptly forgot about it. It got hung and run overnight, killing our production cycle.

In an effort to never have this happen again, I am trying to write a .bat file which runs at 1am to kill SSMS. Its a quick one-liner, but only works if nothing is running...defeating the purpose.

taskkill /IM Ssms.exe

Does anyone know a .bat command to force it to close? I was looking for a way to kill all of my queries, but am wondering if there was a better way to do it.

EDIT: I'm not set on a .bat file if there's another idea. Python in particular is another option.


Solution

  • As per this answer

    You need to use the /f parameter so your command become

    taskkill /f /IM Ssms.exe