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