Note: Blogspot has a funny way to place text into columns. I broke the "for" command line into multiple lines using "\" -- you need to make it back a superlong command line for this to work.@echo off set r=%RANDOM% title "SUPERSECRETTITLE %r%" for /f "usebackq tokens=2" %%a in (`" \ tasklist /v /fi "imagename eq cmd.exe"| \ %windir%\System32\find "SUPERSECRETTITLE %r%" \ "`) do set PID=%%a echo PID is %PID%
Bonus (continuation): Find out if this CMD.exe was started with "/K" so you know to do "exit 0" or "exit /b 0":
The point of all this is that one does not need PowerShell to do useful Win32 scripting.wmic process where (name="cmd.exe" and processid=%PID%)\ get commandline /value | \ %windir%\system32\find " /K " >nul set SLASHK=%ERRORLEVEL%
-ulianov