1. 程式人生 > >BAT指令碼獲取當前cmd.exe程序PID/PPID/資訊(自殺指令碼)

BAT指令碼獲取當前cmd.exe程序PID/PPID/資訊(自殺指令碼)

@ echo off
REM get cmd pid
set TempFile=%TEMP%\sthUnique.tmp
wmic process where (Name="wmic.exe" AND CommandLine LIKE "%%%TIME%%%") get ParentProcessId /value | find "ParentProcessId" >%TempFile%
set /P _string=<%TempFile%
set _pid=%_string:~16%
echo %_pid%

REM get cmd ppid
wmic process where (processid=%_pid%) get ParentProcessId /value | find "ParentProcessId" >%TempFile%
set /P _string=<%TempFile%
set _pid=%_string:~16%
echo %_pid%
...