Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Parent Process ID

Reply
 
Old 02-24-2009   #1 (permalink)
David


 
 

Parent Process ID

I am attempting to determine if a process running locally is orphaned? It
looks like I need to access the th32ParentProcessID member of the
PROCESSENTRY32 structure. Is there a way to read the PROCESSENTRY32 structure
with PowerShell or another method to determine the process parent id?


My System SpecsSystem Spec
Old 02-25-2009   #2 (permalink)
Kiron


 
 

Re: Parent Process ID

Ignore my previous post, I misunderstood your question and thought you just wanted to retrieve the ParentProcessID.
This will filter each process whose parent process is terminated or if its ParentProcessID inaccurately points to a 'parent' process created after it.

$wmi = [wmi]''
$col = gwmi win32_process | ? {
$parent = gwmi win32_process -f "ProcessID='$($_.parentProcessID)'"
$parentCreationDate, $creationDate = $(
if ($parent -and $_.parentProcessID) {
$wmi.ConvertToDateTime($parent.CreationDate),
$wmi.ConvertToDateTime($_.CreationDate)
} else {$null,$null})
!$parent -or $parentCreationDate -gt $creationDate
}
Remove-Variable wmi
$col | ps -ID {$_.processID}

--
Kiron
My System SpecsSystem Spec
Old 02-25-2009   #3 (permalink)
David


 
 

Re: Parent Process ID

Thank you Kiron! Checking the creation dates was an added feature I had not
thought of. I seem to alway overlook wmi when attempting to solve these types
of problems.

"Kiron" wrote:
Quote:

> Ignore my previous post, I misunderstood your question and thought you
> just wanted to retrieve the ParentProcessID.
> This will filter each process whose parent process is terminated or if its
> ParentProcessID inaccurately points to a 'parent' process created after
> it.
>
> $wmi = [wmi]''
> $col = gwmi win32_process | ? {
> $parent = gwmi win32_process -f "ProcessID='$($_.parentProcessID)'"
> $parentCreationDate, $creationDate = $(
> if ($parent -and $_.parentProcessID) {
> $wmi.ConvertToDateTime($parent.CreationDate),
> $wmi.ConvertToDateTime($_.CreationDate)
> } else {$null,$null})
> !$parent -or $parentCreationDate -gt $creationDate
> }
> Remove-Variable wmi
> $col | ps -ID {$_.processID}
>
> --
> Kiron
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Exctracting OU and parent OU name from Active Directory VB Script
Collections Help when in a parent class .NET General
Get parent directory PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46