3

I was looking up the start and tasklist commands, and i noticed 2 things. They both had references to a window title.

start "myTest" /b somefile argA
tasklist /fi "WindowTitle eq myTest"

the thing that confuses me is that the task list isnt returning any matches to me. Is there something i am doing wrong, or do these not reference the same title

3

They sure do refer to the same title. It is the title that appears within the top border of your window. The problem is your START /B switch causes the process to be launched within the same console window, and a window can only have one title. START does not change the title of the window if the /B switch is used.

Run your START command with the /B switch, and you will see that your window title does not change.

Now run the START command without /B and you will see a new window with the correct title. Your TASKLIST command will now find the correct process.

  • maybe start then is not the command I want? I am trying to launch somefile as a passive process, not needing a command line. I want to launch it and then carry on with the script, while still have a pointer / PID to the process so i can kill it later? It is then possible to do something like: start "myTest" somefile argA & like in unix to break the console-process dependancy? – Fallenreaper Apr 12 '16 at 17:22
  • That only seems to work if the command you are starting is actually a cmd shell. start "testprogram" "notepad" followed by tasklist /v | findstr -i testprogram does not find anything. – DavidPostill Apr 12 '16 at 17:22
  • See Trying to track a PID in windows created from the pub command and comments for the background to this question. We have been puzzling over it all afternoon :; – DavidPostill Apr 12 '16 at 17:23
  • @DavidPostill - I believe a more generic way of stating the issue is - Not all programs allow you to set the window title via the START command. Many programs override any value that START tries to establish. – dbenham Apr 19 '16 at 16:49
1

Give a try for this example to start Chrome.exe and kill all its PID(s) after launching it !

@echo off
set MyProcess=Chrome.exe
start "" %MyProcess%
setlocal EnableDelayedExpansion
for /f "TOKENS=2" %%a in ('tasklist /NH /FI "imagename eq %MyProcess%"') do (
    Set PID=%%a & echo The PID of %MyProcess% = !PID! 
    Echo( & Echo To Kill all PID of "%MyProcess%" , just Hit any key & pause 
    Taskkill /PID !PID! /F /T
)
EndLocal
pause

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.