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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.