Windows Management Instrumentation (WMI)

2.2 Perl Example
#!perl

# Simple Perl Script to illustrate use of WMI to gather system information
# and display it in the same format at the Windows Management Console

use Win32::OLE qw(in with);
use Win32::Registry;

# Pick a host that you have the necessary rights to monitor

$host = "snowday.tc.cornell.edu";

# Gather System Information

$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; 

# Gather Computer System Information
 
$sys_set = $Services->InstancesOf("Win32_ComputerSystem");
foreach $sys (in($sys_set)) 
 {  
  $system_name         = $sys->{'Caption'};
  $system_type         = $sys->{'SystemType'};
  $system_manufacturer = $sys->{'Manufacturer'};
  $system_model        = $sys->{'Model'};
 }
 
# Gather Processor Information
$processor_set = $Services->InstancesOf("Win32_Processor");
foreach $proc (in($processor_set)) 
 {
  $proc_description    = $proc->{'Caption'};
  $proc_manufacturer   = $proc->{'Manufacturer'};
  $proc_mhz            = $proc->{'CurrentClockSpeed'};
 }


# Gather BIOS Information

$bios_set = $Services->InstancesOf("Win32_BIOS");
foreach $bios (in($bios_set)) 
 {  
  $bios_info       = $bios->{'Version'};
 }

# Gather Time Zone Information

$loc_set = $Services->InstancesOf("Win32_TimeZone");
foreach $loc (in($loc_set)) 
 {
  $loc_timezone      = $loc->{'StandardName'};  
 }

# Gather Operating System Information

$os_set = $Services->InstancesOf("Win32_OperatingSystem");
foreach $os (in($os_set)) 
 {
  $os_name         = $os->{'Caption'};
  $os_version      = $os->{'Version'};
  $os_manufacturer = $os->{'Manufacturer'};
  $os_build        = $os->{'BuildNumber'};
  $os_directory    = $os->{'WindowsDirectory'};
  $os_locale       = $os->{'Locale'}; 
  $os_totalmem     = $os->{'TotalVisibleMemorySize'};
  $os_freemem      = $os->{'FreePhysicalMemory'};
  $os_totalvirtmem = $os->{'TotalVirtualMemorySize'};
  $os_freevirtmem  = $os->{'FreeVirtualMemory'};
  $os_pagefilesize = $os->{'SizeStoredInPagingFiles'}; 
 }

# Now convert the system's Locale to a string
# Use the Rfc1766 Database stored in the Registry as a lookup table

$main::HKEY_LOCAL_MACHINE->Open("SOFTWARE\\Classes\\MIME\\Database\\Rfc1766",$Rfc1766);
$Rfc1766->GetValues(\%Values);
foreach $key (keys %Values)
 {
  $key = $Values{$key};
  if ($$key[0] eq $os_locale)
   {
    ($lang, $country) = split(/\;/, $$key[2]);
    last;
   } 
 }

print "System Summary Information\n";
print "--------------------------\n";
print "OS Name\t\t\t\t$os_name\n";
print "Version\t\t\t\t$os_version Build $os_build\n";
print "OS Manufacturer\t\t\t$os_manufacturer\n";
print "System Name\t\t\t$system_name\n";
print "System Manufacturer\t\t$system_manufacturer\n";
print "System Model\t\t\t$system_model\n";
print "System Type\t\t\t$system_type\n";
print "Processor\t\t\t$proc_description $proc_manufacturer ~$proc_mhz Mhz\n";
print "BIOS Version\t\t\t$bios_info\n";
print "Windows Directory\t\t$os_directory\n";
print "Locale\t\t\t\t$country\n";  
print "Time Zone\t\t\t$loc_timezone\n";
print "Total Physical Memory\t\t$os_totalmem KB\n";
print "Available Physical Memory\t$os_freemem KB \n";
print "Total Virtual Memory\t\t$os_totalvirtmem KB\n";
print "Available Virtual Memory\t$os_freevirtmem KB\n";
print "Page File Space\t\t\t$os_pagefilesize KB\n";

Output from this Perl script: 

snowday


From the Computer Management application:
 

cmsnow