Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF
- SETLOCAL EnableExtensions DisableDelayedExpansion
- set "_toRun=cmd.exe /C pause" change to meet your circumstances
- set "_where=." sorry testing merely local computer
- set "_toGet=ProcessId ReturnValue"
- set "_ProcessId="
- set "_ReturnValue="
- rem %%G loop to get raw return values from `create` like next two lines
- rem ProcessId = 6476;
- rem ReturnValue = 0;
- for /F "tokens=*" %%G in ('
- wmic /node:"%_where%" process call create "%_toRun%" ^| findstr "%_toGet%"
- ') do (
- rem %%g loop to assign values to variables `_ProcessId` and `_ReturnValue`
- for /F "tokens=1,2 delims=;= " %%g in ("%%~G") do (
- set "_%%~g=%%~h"
- )
- )
- if NOT "%_ReturnValue%"=="0" (
- echo %_toRun% failed, Return Value %_ReturnValue%
- goto :notest
- )
- echo process %_toRun% runs as %_ProcessId%
- rem build WQL query
- set "_query=ProcessId = %_ProcessId% and CommandLine = '%_toRun:=\%'"
- rem loop while queried process runs
- :test
- set "_CommandLine="
- for /F %%G in ('
- wmic /node:"%_where%" process where "%_query%" get CommandLine /value ^| findstr "="
- ') do set "_%%~G"
- if not defined _CommandLine goto :notest
- set _Comman
- >NUL timeout /T 5 /NOBREAK
- goto :test
- :notest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement