Windows batch file : PID of last process? Windows batch file : PID of last process? windows windows

Windows batch file : PID of last process?


For what it worth (question is more than 2 years old) this code do the trick, just change variable according to default browser exe

set "browser=palemoon.exe"tasklist /FI "imagename eq %browser%" /NH /FO csv > task-before.txtstart www.google.comtasklist /FI "imagename eq %browser%" /NH /FO csv > task-after.txt:: fc /L /LB1  test4-Before.txt test4-After.txt | find /I "%browser%"for /f "delims=, tokens=2,*" %%A in ('"fc /L /LB1  task-before.txt task-after.txt | find /I "%browser%""') do set pid=%%ASETLOCAL enabledelayedexpansionpid=!pid:"=!ENDLOCALecho pid is %pid%


This is just an idea, to get you maybe on the way

there is a command called Tasklist

there is a switch called filter /FI with lets you decide what filter parameters you want to output, f.e PID. Output this to a > 1.TXT

start your proces

recheck the watchlist and output to 2.TXT

Then you would have to get creative. COmpare 1 to 2,maybe remove the processes in 1 from the 2.TXTThe remainig PID is what you wanted?


If you have some programming experience, you could create your own console application that accepts command-line parameters and passes them to the Win32 API CreateProcess() function. One of its output values is the spawned process ID, which your app could then return. Then just update your batch file to call your app instead of using START directly.