views:

53

answers:

1

I have a bunch of console host applications hosting WCF services. I'm calling a .bat file as a pre build step to kill any running host instances so that I don't get WCF channel registrations errors(manually killing the console hosts each time before a build is a royal pain).

The .bat file I've created contains the following.

taskkill /T /F /FI "imagename eq Host.vshost.exe"
taskkill /T /F /FI "imagename eq Host.exe"
exit /B 0

This kills both processes. I can see in taskmanager that Host.exe is gone and Host.vshost.exe has a new PID but the Console Window is still up. It seems that cmd.exe is the actual process hosting the console so I then changed the .bat file to this..

taskkill /T /F /FI "imagename eq cmd.exe"

But this kills all cmd.exe windows.

How can I tweak this so that i can target just the specific Console application's cmd window or is there a different command I should be using?

A: 

taskkill has several options to help you narrow down the process you want to kill. For example, is the window title of the CMD.EXE process you want to kill unique (e.g. "Batch Processing" instead of the default "C:\WINDOWS\System32\cmd.exe")? Then use

taskkill /F /T /FI "WINDOWTITLE eq Batch Processing"

If you need to change the title of the target window, you can do so from the target batch file with the command TITLE Your Title Here, or by starting that process with a start "Your Title Here" ... command.

ewall
That works. I changed the window title in the .NET console application and was able to use the Taskkill option to target the window by title. Thanks!!!
Abhijeet Patel
Glad that resolved it for you!
ewall