in reply to caller of perl script

I looked into how to get process hierarchy and argument data on windows, and heres a script that will print out a forest of process nodes, showing the arguments each was started with:
use Win32::ToolHelp ':all'; use Win32::Process::CommandLine; use Tree; my @nodes; for (GetProcesses) { my %h; @h{qw/n_refs pid hid mid n_threads ppid prio flags name/} = @$_; Win32::Process::CommandLine::GetPidCommandLine($h{pid}, $h{args}); push @nodes, Tree->new(\%h); } my @forest; while (my $node = shift @nodes) { my ($parent) = grep {$_->value->{pid} == $node->value->{ppid}} @nodes, map $_->traverse, @forest; $parent ? $parent->add_child($node) : push @forest, $node; } for (map $_->traverse, @forest) { printf "%s%s\n", " " x $_->depth, $_->value->{args} || $_->value->{name}; }

Replies are listed 'Best First'.
Re^2: caller of perl script
by BrowserUk (Patriarch) on Jun 12, 2010 at 05:00 UTC

    Here's a somewhat easier way:

    #! perl -slw use strict; use Win32::Process::Info;; my $pi = new Win32::Process::Info;; my @info = $pi->GetProcInfo( $$ ); my $ppid = $info[0]{ ParentProcessId }; @info = $pi->GetProcInfo( $ppid ); print "Parent process name : ", $info[0]{ ExecutablePath }; print "Command line: ", $info[0]{ CommandLine };

    But as I explained earlier, it's not very useful for the OPs stated requirement as it always gives the same information:

    c:\test>type junk.bat dad c:\test>junk.bat c:\test>dad Parent process name : C:\Windows\System32\cmd.exe Command line: "C:\Windows\System32\cmd.exe"

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.