[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 2 use warnings; 3 use strict; 4 use Getopt::Long; 5 use Pod::Usage; 6 use Win32::OLE; 7 8 # Your usual option-processing sludge. 9 my %opts; 10 GetOptions (\%opts, 'help|h|?', 'remote=s', 'query=s') 11 or pod2usage (2); 12 13 (exists $opts{'help'}) 14 and pod2usage ('-exitstatus' => 0, '-verbose' => 2); 15 16 # Ensure exactly one argument after options. 17 scalar @ARGV == 1 18 or pod2usage (2); 19 20 my ($class) = @ARGV; 21 22 # Bomb out completely if COM engine encounters any trouble. 23 Win32::OLE->Option ('Warn' => 3); 24 25 # Get a handle to the SWbemServices object of the machine. 26 my $computer = Win32::OLE->GetObject (exists $opts{'remote'} 27 ? "WinMgmts://$opts{'remote'}/" 28 : 'WinMgmts:'); 29 30 # Get the SWbemObjectSet of all objects of the class. 31 my $query = "SELECT * FROM $class"; 32 (exists $opts{'query'}) 33 and $query .= " WHERE $opts{'query'}"; 34 print "Executing query: $query\n"; 35 my $instances_set = $computer->ExecQuery ($query); 36 37 # Convert set to Perl array. 38 my @instances = Win32::OLE::Enum->All ($instances_set); 39 40 # Display all properties of an object. 41 sub dump_obj ($) { 42 my ($obj) = @_; 43 # Get set of properties of the class. 44 my $props_set = $obj->{'Properties_'}; 45 46 # Convert set to Perl array. 47 my @props = Win32::OLE::Enum->All ($props_set); 48 foreach my $prop (@props) { 49 my $name = $prop->{'Name'}; 50 printf "%32s ", $name; 51 my $value; 52 if ($prop->{'IsArray'}) { 53 my $elts = $prop->Value(); 54 if (!defined $elts) { 55 $value = "<empty array>"; 56 } 57 else { 58 $value = '<array ' . join ' ', @$elts; 59 $value .= '>'; 60 } 61 } 62 else { 63 $value = $prop->{'Value'}; 64 defined $value 65 or $value = '<undefined>'; 66 } 67 print "$value\n"; 68 } 69 } 70 71 foreach my $instance (@instances) { 72 dump_obj ($instance); 73 print "\n"; 74 } 75 76 exit 0; 77 78 __END__ 79 80 =head1 NAME 81 82 instances.pl - Dump all instances of a WMI class 83 84 =head1 SYNOPSIS 85 86 instances.pl [ options ] <WMI class name> 87 88 Options: 89 90 --help Display help and exit 91 --remote <host> Operate on <host> instead of local machine 92 --query <query> Restrict instances to match WQL query <query> 93 94 =head1 SEE ALSO 95 96 http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_classes.asp 97 http://msdn.microsoft.com/library/en-us/wmisdk/wmi/querying_with_wql.asp
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |