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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.