0

So I'm using the taskkill.exe which comes with Vista and I want it to do something especially complicated..

There are multiple instances of java.exe running, and I want it to find the one that is untitled.. so this is my command:

taskkill /IM java.exe /FI "WINDOWTITLE eq "

I also tried:

taskkill /IM java.exe /FI "WINDOWTITLE ne AutoClicker"

It doesn't work anyways... So is there anyway... to target an untitled process???

PizzaPie
  • 285
  • 1
  • 3
  • 7
  • Find the PID, then kill by pid. – LatinSuD Sep 13 '10 at 08:34
  • @LatinSuD: You have the same problem; namely trying to filter for a window with no title – just then with `tasklist` instead of `taskkill`. – Joey Sep 13 '10 at 12:26
  • Sorry, I completely forgot that I cannot use tasklist because I am running this command on an automated program. It cannot parse PID's, and if it could, it wouldn't be able to tell it's PID from the one it has to end. – PizzaPie Sep 13 '10 at 17:44

1 Answers1

1

You must first find the PID of the untitled process by parsing the results of TASKLIST, and then invoke TASKKILL with the found PID.

Try the following code

@echo off
SETLOCAL enabledelayedexpansion
for /f "tokens=*" %%a in ('TASKLIST /V') do (
  set s=%%a
  set p=!s:~27,5!
  set t=!s:~152,3!
  if '!t!'=='N/A' ECHO TASKKILL /PID !p! /T
)

and after extra-careful testing, remove the ECHO

PA.
  • 28,486
  • 9
  • 71
  • 95