Sorry, brain fart: Win32_PhysicalMemory->Capacity returns number of Bytes of
memory. Multiplying that by 1024 results in number of K's in memory.
Multiplying that by 1024 returns number of M's in memory. I is edjumakated,
I really is.

 

Tal

 

  _____  

From: Duane Bronson [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, July 21, 2004 1:02 PM
To: Tal Cohen
Subject: Re: [Boston.pm] Need help working with WMI...update (making
headway)

 

because I don't have 1048576 memorized.

Tal Cohen wrote:

This is why I post :)
 
Why do you square 1024 in the line: $totalMem /=1024*1024;
 
Tal
 
-----Original Message-----
From: Duane Bronson [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, July 21, 2004 12:20 PM
To: Tal Cohen; [EMAIL PROTECTED]
Subject: Re: [Boston.pm] Need help working with WMI...update (making
headway)
 
 
I don't think you are doing it right.  I have 2 512Meg cards on this 
laptop (Dell Latitude D800 WindowsXP) (total = 1Gig), and this script 
tells me I have 512Meg of memory.  By coincidence, it works correctly on 
a Win2003 desktop with 512Meg of memory (maxcap = 2097152, memdev == 
4).  MaximumCapacity is the largest capacity that computer could have 
with the current memory array.  MemoryDevices is the number of slots 
available.  You are computing the average memory card size which would 
work show physical memory IF you have only 1 card.  Hmm, no - that's not 
right either because I think the desktop has 2 256Meg cards.
 
I think you really need something like this:
#!/bin/perl -w
 
use Win32::OLE qw(in with);
 
my $host = shift @ARGV;
 
$WMI = Win32::OLE->new('WbemScripting.SWbemLocator') || die "Cannot access
WMI on local machine: ", Win32::OLE->LastError;
 
$Services = $WMI->ConnectServer($host) || die "Cannot access WMI on remote
machine: ", Win32::OLE->LastError;
 
$ComputerSysSet = $Services->InstancesOf("Win32_PhysicalMemory");
 
my $totalMem = 0;
foreach $ComputerSystem (in($ComputerSysSet)) {
    $totalMem += $ComputerSystem->{'Capacity'};
}
$totalMem /=1024*1024;
print "There is $totalMem MegaBytes of memory on this system\n";
 
exit 0;
 
 
 
 
 
Tal Cohen wrote:
 
  

I am making headway with my project (and will be sharing as I move
    

forward).
  

At this time, I have been successful retrieving memory information from a
WinXP system. Below is code that will queries and reports how much memory
    

is
  

installed on a system.  You need Win32::OLE for this to work. Can someone
test this on other Windows system and let me know if it works (or if it
    

dies
  

what the error message if any is). The next step for memory will be to
identify how much of the total memory is currently being used.
 
 
 
Thanks,
 
 
Tal Cohen
 
 
 
 
 
use Win32::OLE qw(in with);
 
$WMI = Win32::OLE->new('WbemScripting.SWbemLocator') || die "Cannot access
WMI on local machine: ", Win32::OLE->LastError; 
 
$Services = $WMI->ConnectServer($host) || die "Cannot access WMI on remote
machine: ", Win32::OLE->LastError; 
 
$ComputerSysSet = $Services->InstancesOf("Win32_PhysicalMemoryArray");
 
foreach $ComputerSystem (in($ComputerSysSet)) {
 
           $MaxCap = $ComputerSystem->{'MaxCapacity'};
 
           $MemDev = $ComputerSystem->{'MemoryDevices'};
 
           if ($MaxCap < 1 || $MemDev < 1) {
 
                       $myError = Win32::OLE->LastError;
 
                       print "An error has occured retreiving memory
information:\n";
 
                       print " - $myError -\n";
 
                       print "The maximum capacity retreived was
$MaxCap\n";
 
                       print "The number of memory devices detected was
$MemDev\n";
 
                       print "The total memory capacity of a system is
calculated by\n";
 
                       print "taking the maximum capacity, and dividing it
by the number\n";
 
                       print "of memory devices and then dividing that
number by 1024 (1K)\n";
 
                       
 
           } else {
 
                       $totalMem = $MaxCap / 1024 / $MemDev;
 
           }
 
           print "There is $totalMem MegaBytes of memory on this
system.\n";
 
}
 
exit 0;
 
 
 
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm
 
 
 
    

 
  

 

-- 
  , , ,     |  Duane Bronson
 /|/|/| ,   |  [EMAIL PROTECTED]
( ( ( |/|   |  http://www.nerdlogic.com/
 \    ( |   |  453 Washington St. #4A, Boston, MA 02111
  |    /    |  (617) 515-2909
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to