Created
March 31, 2016 11:36
-
-
Save StephaneTy-Pro/84c94e2bb02b427b12af739b8c084cf9 to your computer and use it in GitHub Desktop.
Batch To See Which PID was launched
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set PROCESSNAME=notepad2.exe | |
::First save current pids with the wanted process name | |
setlocal EnableExtensions EnableDelayedExpansion | |
set "RETPIDS=" | |
set "OLDPIDS=p" | |
for /f "TOKENS=1" %%a in ('wmic PROCESS where "Name='%PROCESSNAME%'" get ProcessId ^| findstr [0-9]') do (set "OLDPIDS=!OLDPIDS!%%ap") | |
SET OLDPIDS | |
::Spawn new process(es) | |
start %PROCESSNAME% | |
for /f "TOKENS=1" %%a in ('wmic PROCESS where "Name='%PROCESSNAME%'" get ProcessId ^| findstr [0-9]') do ( | |
if "!OLDPIDS:p%%ap=zz!"=="%OLDPIDS%" (set "RETPIDS=/PID %%a !RETPIDS!") | |
) | |
@ECHO.NEw PID ARE | |
SET RETPIDS | |
CALL:sleep 5 | |
SET RETPIDS | |
@ECHO DONE | |
GOTO :EOF | |
:sleep -– waits some seconds before returning | |
:: -- %~1 – in, number of seconds to wait | |
FOR /l %%a in (%~1,-1,1) do (ping -n 2 -w 1 127.0.0.1>NUL) | |
goto :eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
credits to : http://stackoverflow.com/questions/9486960/windows-batch-scripting-get-pid-of-just-started-process