Windows batch file: last process PID?

I launch the browser from a batch file.

START "www.google.com" 

I would like to know that the PID of this browser window is running.

On one machine, many browser windows can be launched. I need to find the PID of a process that was only launched by my batch file. I tried the WINDOWTITLE filter. But this is not a good idea, as the names may change in the future. I am using Windows XP / 7

Any help would be greatly appreciated. Thanks.

+7
source share
5 answers

What is it worth (question over 2 years) this code does the trick, just change the variable according to the default browser exe

 set "browser=palemoon.exe" tasklist /FI "imagename eq %browser%" /NH /FO csv > task-before.txt start www.google.com tasklist /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=%%A SETLOCAL enabledelayedexpansion pid=!pid:"=! ENDLOCAL echo pid is %pid% 
+2
source

It's just an idea so you can be on the way.

there is a team called tasklist

There is a switch called filter / FI that allows you to decide which filter parameters you want to display, fe PID. Print this value for> 1.TXT

start your processes

recheck watchlist and output in 2.TXT

Then you will need to be creative. COmpare from 1 to 2, it is possible to delete processes in 1 of 2.TXT The rest of the PID is what you wanted?

0
source

If you have programming experience, you can 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 generated process identifier, which your application can then return. Then simply update the batch file to invoke the application instead of using START directly.

0
source

I am trying to do the same. Although there must be some way to do this, all my actions in Googling do not imply.

Browse robvanderwoude.com for a list of third-party tools and examples. Also see the full list of Sysinternal utilities here .

0
source

I look at this for about 2 hours and I think there is a way to do this, but it requires more details on how Windows handles iexplore.exe for PID ...

I have a working version of the batch file that I wrote, and you will get what you want, BUT , only if its first and last Internet Explorer windows are open.

For some reason, I cannot force the PID to change when opening new browsers, but I can get the results if there is no window open (obviously, because there is no PID)

Anyway, this is what I have ... you should be able to run this on your system, and it will tell you that there are no differences, and this may lead to results if your default browser is Firefox or Chrome or something else ... you just need to make changes to what I provide.

 @echo off IF EXIST c:\temp\pshell.txt del c:\temp\pshell.txt IF EXIST C:\temp\PID1.txt del C:\temp\PID1.txt IF EXIST C:\temp\PID2.txt del C:\temp\PID2.txt IF EXIST C:\temp\PowerFormat.txt del C:\temp\PowerFormat.txt powershell.exe Get-Process iexplore>C:\temp\pshell.txt FOR /F "skip=3 tokens=7 delims= " %%1 IN ( c:\temp\pshell.txt ) DO @echo %%1>> C:\temp\PID1.txt start "title" "www.google.com" powershell.exe Get-Process iexplore>C:\temp\pshell.txt FOR /F "skip=3 tokens=7 delims= " %%2 IN ( c:\temp\pshell.txt ) DO @echo %%2>> C:\temp\PID2.txt FC /L c:\temp\pid1.txt c:\temp\pid2.txt> C:\temp\FileComparison.txt FOR /F "tokens=7 delims=" %%3 IN (c:\temp\FileComparison.txt) DO @echo %%3>C:\temp\DiffPID.txt FINDSTR "FC: no differences encountered" c:\temp\FileComparison.txt IF '%ERRORLEVEL%'=='0' del C:\temp\FileComparison.txt & echo.No PID Found IF NOT '%ERRORLEVEL%'=='0' type c:\temp\FileComparison.txt pause exit 

Let me know if this helps ...

0
source

All Articles