Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras, Hi all
Gintaras, what is the QM function to call to get all the child processes of an exe..
Exemple, say exe file A.exe has B.exe,c.exe as child (lanched when A.exe is started by itself).
I want to be able to kill all childs of A.exe when killing A.exe
Thanks
Posts: 11,872
Threads: 138
Joined: Dec 2002
QM does not have such function. Use Windows API functions or WMI.
If A.exe is your-created, you can use a job object.
http://stackoverflow.com/questions/5320 ... in-windows
Else enumerate processes with CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS 0) and friends, and use PROCESSENTRY32.th32ParentProcessID.
http://stackoverflow.com/questions/1173 ... or-windows
Or WMI, but usually it is very slow.
Posts: 795
Threads: 136
Joined: Feb 2009
nope, a.exe is a genuine program.
Will dig into your advices.
TY
Posts: 11,872
Threads: 138
Joined: Dec 2002
Macro
Macro2757
;gets all child processes of explorer
int pidParent=ProcessNameToId("explorer")
if(!pidParent) ret
ARRAY(int) a; a[]=pidParent
__Handle hs=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS 0)
PROCESSENTRY32 p.dwSize=sizeof(p)
Process32First(hs &p)
rep
,if p.th32ParentProcessID=pidParent
,,out F"pid={p.th32ProcessID} name={&p.szExeFile%%s}"
,,a[]=p.th32ProcessID
,if(!Process32Next(hs &p)) break
;int i
;for i 0 a.len
,;ShutDownProcess a[i] 1
Posts: 795
Threads: 136
Joined: Feb 2009
pure perfection, as usual, you're the boss.
TY
Posts: 795
Threads: 136
Joined: Feb 2009
For records and fellows interested
Function
ProcessusEnfants
function ARRAY(str)&a str'&b
str name
int pidParent=ProcessNameToId(b)
__Handle hs=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS 0)
PROCESSENTRY32 p.dwSize=sizeof(p)
Process32First(hs &p)
rep
,if p.th32ParentProcessID=pidParent
,,
,,name=F"{&p.szExeFile%%s}"
,,a[]=name
,if(!Process32Next(hs &p)) break
called by this
Macro
Macro12
str g="listary"
ARRAY(str) t
ProcessusEnfants(&t &g)
Maybe a native function in next QM version....
Posts: 11,872
Threads: 138
Joined: Dec 2002
This also gets all descendants, ie children of children and so on. Not tested.
Macro
Macro2757
;gets all child/descendant processes of explorer
int pidParent=ProcessNameToId("explorer")
if(!pidParent) ret
ARRAY(int) a; int i
a[]=pidParent
__Handle hs=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS 0)
PROCESSENTRY32 p.dwSize=sizeof(p)
Process32First(hs &p)
rep
,for i 0 a.len
,,if p.th32ParentProcessID=a[i]
,,,out F"pid={p.th32ProcessID} name={&p.szExeFile%%s}"
,,,a[]=p.th32ProcessID
,if(!Process32Next(hs &p)) break
;int i
;for i 0 a.len
,;ShutDownProcess a[i] 1
Posts: 795
Threads: 136
Joined: Feb 2009
yes, working beautifully, as it enhance the found children...much appreciated