Killing a process and all its children processes.... 
Author Message
 Killing a process and all its children processes....

I have script that kills a process but I need to modify it so that it also
kills the any child processes....is there any way to do this?
        -J

'Purpose To kill a process given it Process ID(PID).
'Arugments There is only one argument, the process ID of
'  the process that needs to be killed

set WMI = getobject("winmgmts:")

sQuery = "select * from win32_process " _
       & "where ProcessID=" & Wscript.Arguments(0)
set processes = WMI.execquery(sQuery)

For Each Process in processes
  process.terminate
next



Sat, 07 Feb 2004 10:52:21 GMT  
 Killing a process and all its children processes....
Hi

Doing a newsgroup search with http://groups.google.com/advanced_group_search
the following came up that makes it look like that the answer to your question
is no:

<qoute>

Subject: Re: "bWaitOnReturn" option for WshShell.Run method
Newsgroups: microsoft.public.scripting.wsh
Date: 2000/11/27

"...Is there a way of tracking which processes are spawned by other processes.
..."

If you know that foo.exe will spawn an instance of bar.exe, you *could* use
WMI it track the PIDs
(Process IDs) of instances of bar.exe.  For example, before executing foo.exe,
record the PIDs (if
any) of bar.exe instances.  Execute foo.exe and recheck the PIDs for bar.exe
instances.  The one
that is new is for the new instance of bar.exe spawned by foo.exe.  There
might even be a more
direct way using WMI notification events but that would take a lot more time
to research ;-)...

I don't know if there is a generic technique available to script clients to
track the child
processes of an arbitrary parent process.  If there is one it would probably
involve WMI...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> As a follow on, taking up Michael's point, what, if anything, can be done if
> the process DOES spawn another process then self terminate. Is there a way
> of tracking which processes are spawned by other processes. If this is the
> case, it should be possible to write code which watches an initial process,
> and waits until both it, and any child processes (and children thereof) have
> also terminated! The more I think about it, the more it scares me!

> This is not just an academic question, as I have a genuine use for this.

> Opinions/answers please!

</qoute>
Quote:

> I have script that kills a process but I need to modify it so that it also
> kills the any child processes....is there any way to do this?
>         -J

> 'Purpose To kill a process given it Process ID(PID).
> 'Arugments There is only one argument, the process ID of
> '  the process that needs to be killed

> set WMI = getobject("winmgmts:")

> sQuery = "select * from win32_process " _
>        & "where ProcessID=" & Wscript.Arguments(0)
> set processes = WMI.execquery(sQuery)

> For Each Process in processes
>   process.terminate
> next



Sat, 07 Feb 2004 11:12:13 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Killing a process and all its children processes....

2. Killing a process

3. How do I kill a cscript process programatically?

4. killing processes

5. kill process

6. VBScript Logon Script kills launched process!!!

7. Killing processes

8. Help with script for killing large process

9. Kill a Process by Username

10. Help with script to kill runaway process

11. Newbie needs help killing explorer.exe process in win2000

12. Killing a process with vbscript

 

 
Powered by phpBB® Forum Software