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 Answers 3

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.

4
  • 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? Apr 12, 2016 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, 2016 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, 2016 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, 2016 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
-1

you can easily check for the Pid from your Process you are looking for and kill them later anytime if needed with

 taskkill /pid %PID%

keep in mind that you need the double space after Administator if you search for an cmd process.

Here an fully example how to use it:

https://gist.github.com/robinrm/ecd1ceb1fc295b2e7b125ca82f42cafe

2
  • Welcome to SU. Please edit your answer to explain how exactly does this address the question OP asked. Apr 1, 2023 at 11:13
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 1, 2023 at 11:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .