Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill a process using the window's name of this process with python or bat

Now i have several same process activated in my system. Besides, although these process have same process name, they have different window title name. And sometimes i want to kill a specific window. If i kill process using process name, i may kill a process which should be alive. How can i solve this? How to kill a process using the window's name of this process? (Python or Bat if fine)

for example, if i kill process by process name:

import psutil

PROCNAME = 'server'

def kill():
    for proc in psutil.process_iter():
        if proc.name == PROCNAME:
            proc.kill()

However, now i want to kill process by window's title name.

like image 257
kylejan Avatar asked Jan 18 '26 02:01

kylejan


1 Answers

i have found the solution. i can use bat command like this:

taskkill /fi "WINDOWTITLE eq titleName"
like image 51
kylejan Avatar answered Jan 19 '26 15:01

kylejan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!