http://qs1969.pair.com?node_id=149892

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

Greetings,
I have been writing a script to get all the processes
on a win2k terminal server to do some usages stats.
the main problem i have is that when i run my script to
get the processes on any other win2k machine on the
network it works. However when i try to get all the
processes on the terminal server it just gives the ones
running on the main account, not all of the processes
for all of the users logged in. Has anyone ever done
this before? Here is the code i run to get the
processes. #I got some of the code from a win32 perl
book
# This script uses WMI to generate a process list from remote machine +s. use Win32::OLE qw( in ); use Win32::OLE::Variant; $User = new Win32::OLE::Variant( VT_BYREF | VT_BSTR, "" ); $Domain = new Win32::OLE::Variant( VT_BYREF | VT_BSTR, "" ); $Machine = "myterminalserver.domain.ext" unless( $Machine = shift @ARG +V ); $Machine =~ s#^[\\/]+## if( $ARGV[0] =~ m#^[\\/]{2}# ); # This is the WMI moniker that will connect to a machine's # CIM (Common Information Model) repository $CLASS = "WinMgmts:{impersonationLevel=impersonate}!//$Machine"; # Get the WMI (Microsoft's implementation of WBEM) interface $WMI = Win32::OLE->GetObject( $CLASS ) || die "Unable to connect to \\$Machine:" . Win32::OLE->LastError(); # Get the collection of Win32_Process objects $ProcList = $WMI->InstancesOf( "Win32_Process" ); $~ = PROCESS_HEADER; write; $~ = PROCESS_INFO; # Cycle through each Win32_Process object # and write out its details... foreach $Proc ( in( $ProcList ) ) { $status = $Proc->GetOwner($User,$Domain); write; } sub SortProcs { lc $a->{Name} cmp lc $b->{Name}; } sub FormatNumber { my( $Number ) = @_; my( $Suffix ) = ""; my $K = 1024; my $M = 1024 * $K; if( $M <= $Number ) { $Suffix = "M"; $Number /= $M; } elsif( $K <= $Number ) { $Suffix = "K"; $Number /= $K; } $Number =~ s/(\.\d{0,2})\d*$/$1/; {} while ($Number =~ s/^(-?\d+)(\d{3})/$1,$2/); return( $Number . $Suffix ); } sub FormatDate { my( $Date ) = @_; $Date =~ s/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).*/$1.$2.$3 $ +4:$5:$6/; return( $Date ); } format PROCESS_HEADER = @||| @||||| @||||||||||||||| PID, "User Name", "CPU Time" ---- ------------- --------- . format PROCESS_INFO = @||| @||||| @<<<<<<< $Proc->{'ProcessID'}, $User, $Proc->{'UserModeTime'}*0.0000001 .


Thanks is advance.
Lucas krause

Replies are listed 'Best First'.
Re: Listing *all* Processes on a terminal server over network.
by softworkz (Monk) on Sep 19, 2002 at 19:19 UTC
    Lucas, By trying this myself the only advice I can come up with is to sign in as the domain admin and check the box to show all processes by all users and then try running your code. I'm very interested in other comments.