1

I am writing a batch file to kill all the dependent process for given process ID.I have not completed my code yet.For now my code is

set cmd="wmic process where (ParentProcessId=4192) get ProcessId"
FOR /F %%i IN (' %cmd% ') DO ( 
SET X=%%i 
echo The process is %X%
)

The output of "wmic process where (ParentProcessId=4192) get ProcessId" command is :

ProcessID
3516
<blank space>

In batch it is setting X=ProcessID,3516 and blank space. problem 1: for above code it is not displaying the value of X (in echo). Problem 2: I want those %%i which is integer

kunal
  • 33
  • 4

1 Answers1

0

You can try something like that :

@echo off
set cmd="wmic process where (ProcessId=4192) get ParentProcessId"
Setlocal EnableDelayedExpansion
FOR /F "skip=1 delims=" %%i IN ('%cmd%') DO ( 
    SET X=%%i 
    echo The process is !X!
)
pause
echo The process is %X%
EndLocal
pause

And why you don't use Taskkill command with param /T to terminates the specified process and any child processes which were started by it ?

Hackoo
  • 18,337
  • 3
  • 40
  • 70