use strict; use warnings; $|++; #autoflush output quit(); sub quit { my $sleep = 3; while ( $sleep ){ print "\rQuitting in $sleep sec."; sleep 1; $sleep--; } exit; } #### 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"; }