use strict;
use Win32::Process::Info;
my $pihandle = Win32::Process::Info->new();
my @procinfo = $pihandle->GetProcInfo();
my $ParentPID;
my %ProcNames;
foreach my $PIDInfo (@procinfo) {
$ProcNames{$PIDInfo->{ProcessId}} = $PIDInfo->{Name};
if ($PIDInfo->{ProcessId} == $$) {
$ParentPID = $PIDInfo->{ParentProcessId};
last;
}
}
print "Parent's name is [", $ProcNames{$ParentPID}, "]\n";
if ( $ProcNames{$ParentPID} eq 'OpenWith.exe' or $ProcNames{$ParentPID} eq 'explorer.exe') {
print 'Press ENTER to close the window: ';
<>;
}
else{ print "..exiting normally\n"; }
####
Discipulus@works:D>perl parentpid01.pl
Parent's name is [cmd.exe]
..exiting normally
##
##
Parent's name is [explorer.exe]
Press ENTER to close the window: