The problem contains a multi-part solution. First you need to identify the Window that contains a specified Window Title. Via script, the only way to achieve this is through some COM implementation. WShell.AppActivate allows activating a window by title, but IIRC, it doesn't return a PID or any other useful info. The ActiveX version of AutoIt will allow you to do what you need but don't know how complex the object model is to get one's head around.
Anyway, finding the window title generally only returns the handle to the window itself and not the underlying PID that created the window in the first place. So the next step would be to translate the window handle into a PID value. Again, IIRC, AutoIt has some features that should allow you to do this.
Not wanting you leave you empty-handed, however, there might be an easier way. If the process calls another file or program as an argument, then via WMI, you can query for the command-line value of the process.
With two instances of notepad, open two different files--however, don't open the files inside of notepad. Right-click two files in explorer and select "Open With..." | Notepad.
Then run this sample script:Code:
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colProcesses = $objWMIService.ExecQuery("select CommandLine from win32_process where name='notepad.exe'")
For Each $objProcess in $colProcesses
? "CmdLine = " + $objProcess.CommandLine
Next
You'll be able to see the different files called via the command-line of the originating process.
The big question is if the processes you're looking at include a command-line argument that you can use as a differentiating factor in figuring out which process to terminate. If so, then when you loop to the correct process, killing it should be a simple matter.
Failing that, then I recommend you take a look at the ActiveX version of AutoIt or some other COM object that can provide this information to you.
_________________________
Stevie