Getting System and Hardare Informatin

N

Noname

Hi,
I need to get system and hardware Information using Perl Scripts
like
RAM Size and other memory sizes
Processor speed and Make/model etc
Hardware Make and Model
etc
how can I get these
 
N

Noname

Hi,
I need to get system and hardware Information using Perl Scripts
like
RAM Size and other memory sizes
Processor speed and Make/model etc
Hardware Make and Model
etc
how can I get these

I did found some in formation Using Win32::Registry module , like processor
speed etc, but not Memory size and Exact Model name, on Windows (Sorry for
not mentionaing before)
 
M

Michael Slass

Noname said:
I did found some in formation Using Win32::Registry module , like processor
speed etc, but not Memory size and Exact Model name, on Windows (Sorry for
not mentionaing before)

The Windows Management Interface (WMI) has an OLE object that can give
you all this info. You can get at it through Win32::OLE.

Microsoft's website has VBScript examples for twaddling the WMI COM
object, so those can be stolen and ported to Perl without too much
pain.
 
T

Thomas Kratz

Michael said:
The Windows Management Interface (WMI) has an OLE object that can give
you all this info. You can get at it through Win32::OLE.

Microsoft's website has VBScript examples for twaddling the WMI COM
object, so those can be stolen and ported to Perl without too much
pain.

Since I have done that lately for our software distribution here's a sub
that does exactly that

# Get Inventory Info from the WMI
sub GetWMIInfo {

# init
my $wmi = Win32::OLE->GetObject(
"winmgmts:{impersonationLevel=impersonate,(security)}"
);
unless ( $wmi ) {
print 'error initializing WMI interface, ', Win32::OLE->LastError;
return;
}

my %WMI;

# hardware params
my @inst = in($wmi->InstancesOf('Win32_ComputerSystem'));
$WMI{MEMORY_MB} = int($inst[0]{TotalPhysicalMemory} / 1024**2);
$WMI{CPU_COUNT} = $inst[0]{NumberOfProcessors};

@inst = in($wmi->InstancesOf('Win32_LogicalDisk'));
foreach my $i ( @inst ) {
next if $i->{DeviceID} ne 'C:';
$WMI{DISK_MB_TOTAL} = int($i->{Size} / 1024**2);
$WMI{DISK_MB_FREE} = int($i->{FreeSpace} / 1024**2);
last;
}

@inst = in($wmi->InstancesOf('Win32_Processor'));
$WMI{CPU_MHZ} = $inst[0]{MaxClockSpeed};

# hotfixes
$WMI{HOTFIX} = {};
@inst = in($wmi->InstancesOf('Win32_QuickFixEngineering'));
for my $h ( @inst ) {
if ( $h->{HotFixID} =~ /(\d{5,})/ ) {
$WMI{HOTFIX}{$1} = 1;
}
}

return(\%WMI);
}

For browsing the WMI get the 'WMI Tools' from Microsoft (sorry haven't got
the URL at hand). It should be easy to adapt the sub for fetching other data.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,884
Members
47,419
Latest member
ArturoBres

Latest Threads

Top