Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Get Win32 Total Physical Memory & Available Physical Memory stats
Hello. I've checked CPAN and have searched the net as well and have not been
able to find a Perl script or module that will get me the Total Physical
Memory and Available Physical Memory stats for a remote system, much less an
NT utility. The one utility I found, SYSTEMINFO.EXE can't be used to get
info on an NT4 system and I have plenty of them.  I've found some scripts
that provide task mgr types of info but that's too much.

Any ideas?

Thanks,
Karim



Report this thread to moderator Post Follow-up to this message
Old Post
Karim Wall
10-27-04 08:56 AM


Re: Get Win32 Total Physical Memory & Available Physical Memory stats
"Karim Wall" <mirak63@carolina.rr.com> wrote in
news:UNqdncAz8fvrY-PcRVn-sA@giganews.com:

> Hello. I've checked CPAN and have searched the net as well and have
> not been able to find a Perl script or module that will get me the
> Total Physical Memory and Available Physical Memory stats for a remote
> system, much less an NT utility.

Don't know about pulling information from remote machines but does:

http://tinyurl.com/5rl7e

help?

Sinan.

Report this thread to moderator Post Follow-up to this message
Old Post
A. Sinan Unur
10-27-04 08:56 AM


Re: Get Win32 Total Physical Memory & Available Physical Memory stats
Karim Wall wrote:
> Hello. I've checked CPAN and have searched the net as well and have not be
en
> able to find a Perl script or module that will get me the Total Physical
> Memory and Available Physical Memory stats for a remote system, much less 
an
> NT utility. The one utility I found, SYSTEMINFO.EXE can't be used to get
> info on an NT4 system and I have plenty of them.  I've found some scripts
> that provide task mgr types of info but that's too much.
>
> Any ideas?
>
> Thanks,
> Karim
>
>

An example how to get at WMI information with Win32::OLE can be found here:

http://tinyurl.com/5f2tn

You have to use Win32::OLE as

use Win32::OLE qw/in/;

and change the object creation to

my $wmi = Win32::OLE->GetObject(
" winmgmts:{impersonationLevel=impersonate
,(security)}\\\\<machine>"
);

Thomas

--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-

Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Kratz
10-27-04 01:56 PM


Re: Get Win32 Total Physical Memory & Available Physical Memory stats
Karim Wall wrote:
> Hello. I've checked CPAN and have searched the net as well and have not be
en
> able to find a Perl script or module that will get me the Total Physical
> Memory and Available Physical Memory stats for a remote system, much less 
an
> NT utility. The one utility I found, SYSTEMINFO.EXE can't be used to get
> info on an NT4 system and I have plenty of them.  I've found some scripts
> that provide task mgr types of info but that's too much.
>
> Any ideas?
>
> Thanks,
> Karim
>
>

Try Perl's Win32::OLE and MS's WMI:

use strict;
use warnings;
use Win32::OLE qw[in];

my $host  = $ARGV[0] || '.';
my $wmi   = Win32::OLE->GetObject( "winmgmts://$host/root/cimv2" )
or die Win32::FormatMessage( Win32::OLE::LastError() );

my %instances = (
Win32_PhysicalMemory  => \&get_pmem,
Win32_PerfRawData_PerfOS_Memory => \&get_amem,
);

my $out;
foreach ( keys %instances ) {
my $class = $wmi->InstancesOf( $_ );
$out .= $instances{ $_ }->( $class );
}
print $out;

sub get_pmem {
my $class = shift;
my $total;
$total +=  $_->{Capacity} foreach in($class);
return "Physical Memory: $total\n";
}

sub get_amem {
my $class = shift;
my $amem;
$amem .= join ' ', $_->{AvailableBytes} foreach in($class);
return "Available Memory: $amem\n";
}


Good resources:

Basics of using Win32:OLE & WMI:
http://www.ntmag.com/WindowsScripti...9828/19828.html

WMI Win32 clases:
http://msdn.microsoft.com/library/d.../>
classes.asp

HTH - keith

Report this thread to moderator Post Follow-up to this message
Old Post
ko
10-27-04 01:56 PM


Re: Get Win32 Total Physical Memory & Available Physical Memory stats
"ko" <kuujinbo@hotmail.com> wrote in message
news:2u9g2sF27lsdpU1@uni-berlin.de...
> Karim Wall wrote: 
>
> Try Perl's Win32::OLE and MS's WMI:
>
> use strict;
> use warnings;
> use Win32::OLE qw[in];
>
> my $host  = $ARGV[0] || '.';
> my $wmi   = Win32::OLE->GetObject( "winmgmts://$host/root/cimv2" )
>             or die Win32::FormatMessage( Win32::OLE::LastError() );
>
> my %instances = (
>   Win32_PhysicalMemory  => \&get_pmem,
>   Win32_PerfRawData_PerfOS_Memory => \&get_amem,
> );
>
> my $out;
> foreach ( keys %instances ) {
>   my $class = $wmi->InstancesOf( $_ );
>   $out .= $instances{ $_ }->( $class );
> }
> print $out;
>
> sub get_pmem {
>   my $class = shift;
>   my $total;
>   $total +=  $_->{Capacity} foreach in($class);
>   return "Physical Memory: $total\n";
> }
>
> sub get_amem {
>   my $class = shift;
>   my $amem;
>   $amem .= join ' ', $_->{AvailableBytes} foreach in($class);
>   return "Available Memory: $amem\n";
> }
>
>
> Good resources:
>
> Basics of using Win32:OLE & WMI:
> http://www.ntmag.com/WindowsScripti...9828/19828.html
>
> WMI Win32 clases:
> http://msdn.microsoft.com/library/d...
2_classes.asp
>
> HTH - keith

I noticed "my $host  = $ARGV[0]". I assumed that this was a target remote
server. However, I get  "Too many parameters" error when I run SCRIPT.PL
SERVERNAME. Is this what you intended?
Thanks,
Karim



Report this thread to moderator Post Follow-up to this message
Old Post
KWall
10-27-04 08:57 PM


Re: Get Win32 Total Physical Memory & Available Physical Memory stats
KWall wrote:
> "ko" <kuujinbo@hotmail.com> wrote in message

[snip code]

> I noticed "my $host  = $ARGV[0]". I assumed that this was a target remote
> server. However, I get  "Too many parameters" error when I run SCRIPT.PL
> SERVERNAME. Is this what you intended?
> Thanks,
> Karim
>

Yes, that's how it works. Don't know why you're having problems, check
perldiag against the exact error you're getting. Tested with ActiveState
Perl 5.8.4, Win32::OLE 0.1701 and Cygwin Perl 5.8.2, Win32::OLE 0.1502.

Try hard-coding the hostname/IP and see if that works. You said that you
have plenty of hosts to query, so I assume that you're either going to
get a list of hosts from a text file or database lookup anyway.

HTH - keith

Report this thread to moderator Post Follow-up to this message
Old Post
ko
10-28-04 01:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:47 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.