Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. @ECHO OFF
  2. SETLOCAL EnableExtensions DisableDelayedExpansion
  3.  
  4. set "_toRun=cmd.exe /C pause" change to meet your circumstances
  5. set "_where=." sorry testing merely local computer
  6.  
  7. set "_toGet=ProcessId ReturnValue"
  8. set "_ProcessId="
  9. set "_ReturnValue="
  10. rem %%G loop to get raw return values from `create` like next two lines
  11. rem ProcessId = 6476;
  12. rem ReturnValue = 0;
  13. for /F "tokens=*" %%G in ('
  14. wmic /node:"%_where%" process call create "%_toRun%" ^| findstr "%_toGet%"
  15. ') do (
  16. rem %%g loop to assign values to variables `_ProcessId` and `_ReturnValue`
  17. for /F "tokens=1,2 delims=;= " %%g in ("%%~G") do (
  18. set "_%%~g=%%~h"
  19. )
  20. )
  21. if NOT "%_ReturnValue%"=="0" (
  22. echo %_toRun% failed, Return Value %_ReturnValue%
  23. goto :notest
  24. )
  25. echo process %_toRun% runs as %_ProcessId%
  26.  
  27. rem build WQL query
  28. set "_query=ProcessId = %_ProcessId% and CommandLine = '%_toRun:=\%'"
  29.  
  30. rem loop while queried process runs
  31. :test
  32. set "_CommandLine="
  33. for /F %%G in ('
  34. wmic /node:"%_where%" process where "%_query%" get CommandLine /value ^| findstr "="
  35. ') do set "_%%~G"
  36. if not defined _CommandLine goto :notest
  37. set _Comman
  38. >NUL timeout /T 5 /NOBREAK
  39. goto :test
  40.  
  41. :notest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement