#119758 - 2004-05-18 09:34 PM
Re: Child PID
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
What about -
PsInfo
PsKill
Kent
|
Top
|
|
|
|
#119763 - 2004-05-19 04:04 PM
Re: Child PID
|
Richie19Rich77
Seasoned Scripter
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
PSList only shows parent processes.
Thanks Anyhow.
Rich
|
Top
|
|
|
|
#119764 - 2004-05-19 04:12 PM
Re: Child PID
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You can enumerate the threads from "Win32_Thread" and link back to the parent process using ProcessHandle - Hurrah
Unfortunately the "Name" and "Caption" fields are empty, so it is not possible to identify the thread - Boo
|
Top
|
|
|
|
#119765 - 2004-05-20 12:12 AM
Re: Child PID
|
Richie19Rich77
Seasoned Scripter
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
I am glad in a funny way that no one has solved this problem.
Thanks guys for your help, but this problem may have to be left unsolved.
Thanks
|
Top
|
|
|
|
#119766 - 2004-05-20 02:13 AM
Re: Child PID
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
how about this as an endaround...
enum all PIDs before starting the install/app and dump into an array start the app enum the PIDs again discarding the ones that exist in the first array
then you can discard the ones with processnames not what you are looking for
it is a definite kludge.. but you may get what you are looking for
|
Top
|
|
|
|
#119767 - 2004-05-20 05:10 AM
Re: Child PID
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
Have your tried PrcView?
There is a windows version and a command line version.
Quote:
Displays complete task tree – parent/child relationships for all processes in the system
|
Top
|
|
|
|
#119771 - 2004-05-20 05:38 PM
Re: Child PID
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
As it was an interesting challenge, here is an example of how to do it.
This takes Rads method a little further, to cater for the wrinkles I've talked about in the previous post.
The process finds all the active NTDVM process headers, and then identifies all the threads in the processes.
It then starts the Win16 application, and checks for all the threads again, recording any new ones.
Finally, it monitors the "new" threads, and exits with a message when one of them closes.
- If you need to keep an application running, just use this and restart when it closes.
- If you need to check whether the application is already running, then use this technique to record the thread details in the registry or an ini file after you start the application.
When you next try to start the application, use the saved settings to check whether the process is still running or not.
Code:
Break ON $=SetOption("Explicit","ON") $=SetOption("WrapAtEOL","ON") $=SetOption("ASCII","ON") Dim $sExePath Dim $aiExistThreads, $aiNewThreads Dim $iThread Dim $sThreadList Dim $iCheckInterval Global $oWMIService $iCheckInterval=3 ; How often do we check if application is still active $sExePath="C:\Program Files\JETFRM41\JFDESIGN.EXE" ; What is the application to run? $oWMIService = GetObject("winmgmts:\\.\root\cimv2") If @ERROR "Cannot access WMI sevrice, error is " @ERROR ": " @SERROR ? Exit @ERROR EndIf $aiExistThreads=GetThreadHandles(GetProcessList('Where Caption="NTVDM.EXE"')) Run $sExePath Sleep 1 $aiNewThreads=GetThreadHandles(GetProcessList('Where Caption="NTVDM.EXE"')) $sThreadList="" For Each $iThread in $aiNewThreads "Checking "+$iThread+": " If $iThread If (AScan($aiExistThreads,$iThread)+1) "Existing thread" ? Else "New thread" ? $sThreadList=$sThreadList+","+$iThread EndIf EndIf Next If $sThreadList Dim $aiThreads Dim $colThread, $oThread Dim $i, $bThreadRunning $sThreadList=SubStr($sThreadList,2) $aiThreads=Split($sThreadList,",") ? "Monitoring application threads: "+$sThreadList ? While Not KBHit() For Each $iThread In $aiThreads $bThreadRunning=0 @TIME+" Checking "+$iThread+" is still running " $colThread=$oWMIService.ExecQuery('Select Handle from Win32_Thread Where Handle="'+$iThread+'"',,48) For Each $oThread In $colThread $bThreadRunning=1 Next If $bThreadRunning "OK" ? Else "Stopped" ? ? "*** APPLICATION HAS PROBABLY CLOSED ***" ? Exit 0 EndIf Next Sleep $iCheckInterval Loop Get $ Else "**ERROR** Application failed to start, was already started (single instance only) or was too slow!" ? EndIf Exit 0 Function GetProcessList(Optional $sWhereClause) Dim $colProcess,$oProcess,$sProcessList $colProcess=$oWMIService.ExecQuery('Select Handle from Win32_Process '+$sWhereClause,,48) For Each $oProcess In $colProcess $sProcessList=$sProcessList+"|"+$oProcess.Handle Next $GetProcessList=Split(SubStr($sProcessList,2),"|") EndFunction Function GetThreadHandles($aiPidList) Dim $iPid Dim $colThread, $oThread, $sThreadList For Each $iPid In $aiPidList If $iPid "Checking for threads in process "+$iPid ? $colThread=$oWMIService.ExecQuery('Select Handle from Win32_Thread Where ProcessHandle="'+$iPid+'"',,48) For Each $oThread in $colThread " Found thread "+$oThread.Handle ? $sThreadList=$sThreadList+"|"+$oThread.Handle Next EndIf Next $GetThreadHandles=Split(SubStr($sThreadList,2),"|") EndFunction
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 259 anonymous users online.
|
|
|