WMI is a standard way that Microsoft is giving access to product data
like the OS Name.  The URL below should help if you need any other data
like numbers for the oslevel as opposed to the name of it..  Of
particular interest might be the "OperatingSystemSKU" and
"OSProductSuite".  

One of my particularly favorite values in this WMI Class is
"PAEEnabled"..  I like to verify if any of my administrative brethren
have forgotten to enable large memory support when the total memory in
the system is greater than 4GB.

"winmgmts:\\\\." is shorthand for the local computer.  Where as,
"winmgmts:\\\\somecomputer" would be a remote system.

P.S. In Vista, typically remote WMI Access is turned off by default
(firewall hardening and all)... 

HTH

Steven

http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx

#----------------------
use Win32::OLE qw(in);

$objWMI = Win32::OLE->GetObject("winmgmts:\\\\.\\root\\cimv2");


$oses = $objWMI->ExecQuery("select Caption,OSProductSuite from
Win32_OperatingSystem");

if (Win32::OLE->LastError() != 0) {
  print "Error Connecting to WMI: " . Win32::OLE->LastError();
  $osname = "Unknown";
}
foreach $os (in $oses) {
  print $os->{Caption}."\n";
}
________________________________

        From: perl-win32-users-boun...@listserv.activestate.com
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of
Michael Cohen
        Sent: Wednesday, August 19, 2009 4:40 PM
        To: perl-win32-users@listserv.ActiveState.com
        Subject: Determining Vista Editions
        
        

        To whomever knows the answer: 
        
        I have been using the Win32::GetOSVersion() function for many
years in order to pull the Windows OS level.  However, I now have a new
need to determine whether or not the OS is Windows Vista Home Basic (or
for that matter, other various editions).  I do not see how to pull that
information from GetOSVersion().  From what I can find on the web, I
somehow need to use the "GetProductInfo" call from the "kernel32" DLL. 
        
        I have tried the following code to try to pull the information
from my Vista 32 Ultimate, but cannot seem to get a valid response: 
        
        ---- Cut here ---- 
        #!/usr/bin/perl -w 
        
        use Win32; 
        use Win32::API; 
        use strict; 
        
        my @oslevel = Win32::GetOSVersion(); 
        
        my ($osMaj, $osMin, $spMaj, $spMin); 
        
        printf("OS String:       %s\n", $oslevel[0]); 
        printf("OS ID:           %s\n", $oslevel[4]); 
        printf("OS Major:        %d\n", $osMaj = int($oslevel[1])); 
        printf("OS Minor:        %d\n", $osMin = int($oslevel[2])); 
        printf("OS Build:        %s\n", $oslevel[3]); 
        printf("OS SP Major:     %d\n", $spMaj = int($oslevel[5])); 
        printf("OS SP Minor:     %d\n", $spMin = int($oslevel[6])); 
        printf("OS SuiteMask:    0x%08x\n", $oslevel[7]); 
        printf("OS ProductType:  %s\n", $oslevel[8]); 
        
        my $prodInfo = 0xFFFFFFFF;   # initialize with invalid value 
        my $prodInfoPtr = \$prodInfo; 
        
        if (($oslevel[1] == 6) && ($oslevel[2] == 0)) { 
          my $GetProductInfo = new Win32::API("kernel32",
"GetProductInfo", 
                                              "NNNNP", "I"); 
          my $rc = $GetProductInfo->Call($osMaj, $osMin, 
                                         $spMaj, $spMin, $prodInfoPtr); 
        
          printf("\nRC =             %d\n", $rc); 
          printf("Product Info:    0x%x\n", $prodInfo); 
          printf("Product Info:    0x%x\n", $$prodInfoPtr); 
        } 
        
        ---- Cut here ---- 
        
        
        The information about this call is from this link: 
            http://msdn.microsoft.com/en-us/library/ms724358(VS.85).aspx
<http://msdn.microsoft.com/en-us/library/ms724358(VS.85).aspx>  
        
        Since the response from the GetProductInfo() command is put into
the DW pointer, I have initialized the variable to 0xFFFFFFFF to ensure
it is a double; however, the variable does not appear to be updated via
the GetProductInfo() command (it remains 0xFFFFFFFF) and the $rc is set
to 1.  FWIW, I have also tried to pass the variable directly (i.e., not
the ptr). 
        
        What am I doing wrong?  Is there a better way to get this
information instead of using the GetProductInfo() command from the
"kernel32" DLL? 
        
        Any help would greatly be appreciated. 
        
        Regards,
        Michael Cohen

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to