WMI in action! I was running SSMS 2016 and it locked up on me. So while I waited for it to become responsive I started up SSMS 2014. Still locked, but which do I kill in taskman? (The easy answer, is, of course: change the open query and then look in Applications, not Processes). I didn’t think of that, so used WMI. You could also get fancy and figure out which is the oldest instance of SSMS and do it that way.
Pretty simple: Tell it the path (which is 130 for SSMS 2016), and kill that.
Click through for the script. You can do more than just kill processes this way. Think of a scenario in which you create a whitelist of valid processes and regularly check to see if anything outside that whitelist is running. It’s a little more difficult to do than this script, but not that much tougher.