4

I could not find help to this specific question, and I wonder if it has a solution. I have multiple instances of a program running on Windows 7. How can I kill a specific window (maybe based on the filename that is open)?

Background: I have a client application for an ETL software (SAS EG) on my desktop and routinely something goes wrong and a session freezes. But I have many sessions open at the same time, i.e. multiple instances of the program running on my desktop, each having their own session on the remote server. I want to kill just the one that freezed and continue working with the other instances. I know it's possible, I can kill a single instance from Task Manager, but it's a russian roulette since the processes can't be distinguished from one another in Task Manager afaik. Thanks a lot for any help.

Probel
  • 43
  • Is there any difference between the instances like command line options or application path etc? You may kill the process with the associated process id e.g. TASKKILL /PID 1230 /PID 1241 /PID 1253 /T – Biswapriyo Aug 01 '17 at 13:14
  • 1
    If you use SysInternals' Process Explorer you can see all the files open to a process and/or find all processes which have a file open (partial matching can be used). – AFH Aug 01 '17 at 13:26
  • Do the Windows have different titles? – DavidPostill Aug 01 '17 at 13:26
  • @AFH thanks, sounds good. but unfortunately my organization doesn't give us local admin rights so I might not be able to use it. – Probel Aug 01 '17 at 13:41
  • @DavidPostill yes, the windows have differend titles according to the filename that is open (in this case project name). But the titles cannot be seen in Task Manager or either with tasklist command – Probel Aug 01 '17 at 13:43
  • Process Explorer does not need installation: it is run directly from the directory where you unzipped it. This should be entirely possible without administrator rights, unless there is a policy to prevent the execution of unapproved programs. Since it is a Microsoft utility, you should be able to get it approved without difficulty. – AFH Aug 01 '17 at 13:59
  • @AFH well you are perfectly right. this solves my problem 100%, though I'm still amazed that there is no obvious native solution. Anyways, thanks a lot! – Probel Aug 01 '17 at 14:10
  • @user3589177 . . . A couple posts you might find helpful with this task "potentially"; let me know if you have any questions, issues, etc. 1. https://superuser.com/questions/1102108/writing-a-batch-file-to-copy-network-file-and-open-it-then-close-and-loop/1102120#1102120 and 2. https://superuser.com/questions/1002737/how-to-use-wmic-to-kill-a-cmd-exe-instance-searching-by-its-command-line/1005056#1005056 . . . You may just need a way to store the PID for each instance and then a way to reference those as needed, etc. This should be possible – Vomit IT - Chunky Mess Style Aug 01 '17 at 14:47
  • 1
    Additionally, TASKLIST /V does show the Window title. – Vomit IT - Chunky Mess Style Aug 01 '17 at 14:54

1 Answers1

5

How can I kill a specific window (maybe based on the filename that is open)?

the windows have different titles according to the filename that is open (in this case project name).

You can use taskkill to kill processes that have windows with a specified title.

Example

Given the following window:

enter image description here

The command to kill that instance of notepad which is editing a file called test.txt is:

taskkill /f /fi "windowtitle eq test.txt*"

Output:

>taskkill /f /fi "windowtitle eq test.txt*"
SUCCESS: The process with PID 5356 has been terminated.

Notes:

  • Replace test.txt* with a string that uniquely identifies your application's window.

Further Reading

DavidPostill
  • 156,873