Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Processing processes
#1
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
#2
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.
#3
nope, a.exe is a genuine program.

Will dig into your advices.

TY
#4
Macro Macro2757
Code:
Copy      Help
;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
#5
pure perfection, as usual, you're the boss.

TY
#6
For records and fellows interested

Function ProcessusEnfants
Code:
Copy      Help
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
Code:
Copy      Help
str g="listary"
ARRAY(str) t
ProcessusEnfants(&t &g)


Maybe a native function in next QM version....
#7
This also gets all descendants, ie children of children and so on. Not tested.

Macro Macro2757
Code:
Copy      Help
;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
#8
yes, working beautifully, as it enhance the found children...much appreciated


Forum Jump:


Users browsing this thread: 1 Guest(s)