(Perl) using WMI to get system information


/ Published in: Perl
Save to your folder(s)

# useful links:
# (WMI space definition) http://msdn.microsoft.com/en-us/library/aa394084(VS.85).aspx
# (OLE usage on CPAN) http://cpan.uwinnipeg.ca/htdocs/Win32-OLE/Win32/OLE.html#Object_methods_and_properties


Copy this code and paste it in your HTML
  1. #!/usr/bin/perl -w
  2.  
  3. # use bin\perl.exe wmi.pl to run.
  4. # have fun!
  5. # 2009/6/17 twitter.com/vinocui
  6. #
  7. # useful links:
  8. # (WMI space definition) http://msdn.microsoft.com/en-us/library/aa394084(VS.85).aspx
  9. # (OLE usage on CPAN) http://cpan.uwinnipeg.ca/htdocs/Win32-OLE/Win32/OLE.html#Object_methods_and_properties
  10. #
  11.  
  12. use Win32::OLE;
  13.  
  14. #my $wmi = Win32::OLE->GetObject("winmgmts://./root/cimv2") or die "failed to retrieve cimv2.";
  15. # winmgmts means to access WMI service.
  16.  
  17. my $wmi = Win32::OLE->GetObject("WinMgmts://./root/cimv2") or die "Failed: GetObject\n";
  18. my $list, my $v;
  19.  
  20.  
  21. $list = $wmi->InstancesOf("Win32_Processor") or die "Failed: InstancesOf\n";
  22.  
  23. foreach $v (Win32::OLE::in $list){
  24. print "CPU:\n";
  25. print "\t", $v->{Name}, "\n";
  26. print "\t", $v->{Caption}, "\n";
  27. }
  28.  
  29. $list = $wmi->InstancesOf("Win32_OperatingSystem") or die "Failed: InstancesOf\n";
  30.  
  31. foreach $v (Win32::OLE::in $list){
  32. print "OS:\n";
  33. print "\t", $v->{Name}, "\n";
  34. }
  35.  
  36. 0;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.