Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How to generate a process list from a Remote XP Machine using Perl and WMI

by perllee (Novice)
on Nov 26, 2008 at 06:10 UTC ( [id://726016]=perlquestion: print w/replies, xml ) Need Help??

perllee has asked for the wisdom of the Perl Monks concerning the following question:

Hi,friends:how to generate a process list from a Remote XP Machine using Perl and WMI? The following are my ways:
use Win32; use Win32::OLE; #$machine= shift || Win32::NodeName(); my $machine="WH2851030605387"; #The office of another PC $class = "WinMgmts:{impersonationLevel=impersonate}!//$machine"; + $wmi = Win32::OLE->GetObject($class); $plist = $wmi->InstancesOf("Win32_Process"); $~ = PROC_LIST; write; $~ = PROC_INF; $n = 0; foreach $Proc (Win32::OLE::in( $plist )){ write; $n++; } print " ===========================\n"; print " -> Processes number : $n <-\n"; print " ==========================="; # -------------------------------------------------------------------- +--------- format PROC_LIST = @||| @|||||||||||||||| @||||||| "PID", "Process Name", " Memory" ---- ----------------- -------- . format PROC_INF = @<<< @<<<<<<<<<<<<<<<< @<<<<<<< $Proc->{'ProcessID'},$Proc->{'Name'}, $Proc->{'PeakWorkingSetSize'} .
Implementation of the code,Erroe:

C:\Documents and Settings\lisuzhong\Desktop>perl -w procList.txt

Win32::OLE(0.1707) error 0x800706ba: "RPC " after character 0 in "WinMgmts:{impersonationLevel=impersonate}!//WH2851030605387" at procList.txt line 8

eval {...} called at procList.txt line 8 Can't call method "InstancesOf" on an undefined value at procList.txt line 9. ------------------------------------------

Above,should be how do we solve this?

Thanks.

Replies are listed 'Best First'.
Re: How to generate a process list from a Remote XP Machine using Perl and WMI
by Anonymous Monk on Nov 26, 2008 at 07:51 UTC
Re: How to generate a process list from a Remote XP Machine using Perl and WMI
by pKai (Priest) on Nov 26, 2008 at 12:47 UTC

    Your code works for me, if my account is admin on the remote machine.

    If the machine is operational, but I'm not an admin there, I get: 'error 0x80070005: "Access is denied"'.

    This is different to your 'error 0x800706ba: "RPC "', which looks somewhat mutilated and probably originally was displayed as 'error 0x800706ba: "The RPC server is unavailable"'.

    I got the latter message, if I try to access a non-existent machine.

Re: How to generate a process list from a Remote XP Machine using Perl and WMI
by Bloodnok (Vicar) on Nov 26, 2008 at 12:11 UTC
    It won't solve your problem per-se, but you should be checking for error(s) from Win32::OLE->GetObject e.g. (extract from Win32 Perl Scripting The Administrators Handbook - Roth)
    $wmi = Win32::OLE->GetObject($class) || die "Cannot connect to machine: $class - " . Win32::OLE->LastError( +);

    You are sure that the remote machine has WinMgmts.exe installed - if not, it won't support WMI.

    A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://726016]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-28 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found