(Perl) using WMI to get video memory information


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

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


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. # http://msdn.microsoft.com/en-us/library/aa394373(VS.85).aspx
  22. # Minimum supported client Windows 2000 Professional
  23. # Minimum supported server Windows 2000 Server
  24. $list = $wmi->InstancesOf("Win32_Processor") or die "Failed: InstancesOf\n";
  25.  
  26. foreach $v (Win32::OLE::in $list){
  27. print "CPU:\n";
  28. print "\t", $v->{Name}, "\n";
  29. print "\t", $v->{Caption}, "\n";
  30. }
  31.  
  32. # http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx
  33. # Windows Server 2003, Windows XP, Windows 2000, and Windows NT 4.0:
  34. # If a computer has multiple operating systems installed, this class only returns an
  35. # instance for the currently active operating system.
  36. $list = $wmi->InstancesOf("Win32_OperatingSystem") or die "Failed: InstancesOf\n";
  37.  
  38. foreach $v (Win32::OLE::in $list){
  39. print "OS:\n";
  40. print "\t", $v->{Name}, "\n";
  41. }
  42.  
  43.  
  44. # http://msdn.microsoft.com/en-us/library/aa394512(VS.85).aspx
  45. # Windows Server 2003, Windows XP, Windows 2000, and Windows NT 4.0: This class is supported.
  46. $list = $wmi->InstancesOf("Win32_VideoController") or die "Failed: InstancesOf\n";
  47. foreach $v (Win32::OLE::in $list){
  48. print "Video Memory:\n";
  49. print "\t", $v->{Description}, "\n";
  50. print "\t", $v->{AdapterRAM}/1024/1024, "MBytes \n";
  51. }
  52.  
  53.  
  54. 0;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.