line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Win32::WMIC; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
47141
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
777
|
use DBIx::Simple; |
|
1
|
|
|
|
|
26840
|
|
|
1
|
|
|
|
|
30
|
|
7
|
1
|
|
|
1
|
|
1097
|
use SQL::Abstract; |
|
1
|
|
|
|
|
11482
|
|
|
1
|
|
|
|
|
597
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Win32::WMIC - Access to the MS Windows Management Instrumentation Utility! |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.01 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
WMIC extends WMI for operation from several command-line interfaces and |
25
|
|
|
|
|
|
|
through batch scripts. Understand? |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Essentially, MS Windows captures a crap-load of information about the |
28
|
|
|
|
|
|
|
system, users, hadware, etc and now makes it available via the wmic |
29
|
|
|
|
|
|
|
command-line utility. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
See this URL for more details: [last checked Mon Dec 28 21:42:44 2009 ] |
32
|
|
|
|
|
|
|
http://technet.microsoft.com/en-us/library/bb742610.aspx |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Use it in Perl... |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use Win32::WMIC; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $wmic = Win32::WMIC->new(); |
39
|
|
|
|
|
|
|
my $csv = $wmic->query('process list')->data; # get processes |
40
|
|
|
|
|
|
|
my $data = $wmic->parse; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 new |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
I |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
new B |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
no arguments |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
new B |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $wmic = Win32::WMIC->new; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
takes 0 arguments |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
example: |
61
|
|
|
|
|
|
|
my $wmic = Win32::WMIC->new; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new { |
66
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
67
|
0
|
|
|
|
|
|
my $self = {}; |
68
|
0
|
|
|
|
|
|
bless $self, $class; |
69
|
0
|
|
|
|
|
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 query |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
I |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
query B |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=over 3 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item L<$query|/"$query"> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
query B |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$wmic->query($query); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
takes 1 argument |
89
|
|
|
|
|
|
|
1st argument - required |
90
|
|
|
|
|
|
|
$query - a single valid wmic command string |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
example: |
93
|
|
|
|
|
|
|
my $query = 'useraccount list breif'; |
94
|
|
|
|
|
|
|
$wmic->query($query); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub query { |
99
|
0
|
|
|
0
|
1
|
|
my ($self, $query, $produce) = @_; |
100
|
0
|
0
|
|
|
|
|
die "No query specified" unless $query; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $output = ''; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# other formats disabled currently |
105
|
0
|
|
|
|
|
|
$produce = 'csv'; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if ($produce) { |
108
|
0
|
0
|
|
|
|
|
if ($produce eq "csv") { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$produce = "CSV"; |
110
|
0
|
|
|
|
|
|
$output = '/format:csv.xsl'; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
elsif ($produce eq "tab") { |
113
|
0
|
|
|
|
|
|
$produce = "Tab"; |
114
|
0
|
|
|
|
|
|
$output = ''; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif ($produce eq "xml") { |
117
|
0
|
|
|
|
|
|
$produce = "XML"; |
118
|
0
|
|
|
|
|
|
$output = '/format:rawxml.xsl'; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
0
|
|
|
|
|
|
die "Formatting not supported, $query"; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else { |
125
|
0
|
|
|
|
|
|
$produce = 'Tab'; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
$self->{query} = "$query $output"; |
128
|
0
|
|
|
|
|
|
$self->{query} =~ s/^\s+|\s+$//g; |
129
|
0
|
|
|
|
|
|
$self->{format} = $produce; |
130
|
0
|
|
|
|
|
|
$self->{data} = eval {`wmic $self->{query}`}; |
|
0
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
$self->{data} =~ s/^[\r\n\s]+//g; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return $self; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 data |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
I
|
139
|
|
|
|
|
|
|
from the wmic query> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
data B |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
no arguments |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
data B |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$wmic->data; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
takes 0 arguments |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
example: |
152
|
|
|
|
|
|
|
my $raw_resultset = $wmic->data; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub data { |
157
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
158
|
0
|
0
|
|
|
|
|
die "No resultset exists" unless $self->{data}; |
159
|
0
|
|
|
|
|
|
return $self->{data}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 parse |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
I
|
165
|
|
|
|
|
|
|
resultset> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
parse B |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 3 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item L<\%where|/"\%where">, L<\@order|/"\@order"> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=back |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
parse B |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $data = $wmic->parse; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
takes 2 arguments |
180
|
|
|
|
|
|
|
1st argument - optional |
181
|
|
|
|
|
|
|
$where - a SQL::Abstract hashref where-clause construct |
182
|
|
|
|
|
|
|
2nd argument - optional |
183
|
|
|
|
|
|
|
$order - a SQL::Abstract arrayref order-clause construct |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
example: |
186
|
|
|
|
|
|
|
my $data = $wmic->parse; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub parse { |
191
|
0
|
|
|
0
|
1
|
|
my ($self, $where, $order) = @_; |
192
|
0
|
0
|
|
|
|
|
die 'No data available to parse' if !$self->{data}; |
193
|
0
|
0
|
|
|
|
|
die 'Format unknown' if !$self->{format}; |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
my $db = DBIx::Simple->connect('dbi:AnyData(RaiseError=>1):'); |
196
|
0
|
|
|
|
|
|
$db->dbh->func( 'resultset', $self->{format}, [$self->data], 'ad_import'); |
197
|
0
|
|
|
|
|
|
my $results = $db->select("resultset", "*", $where, $order); |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
return $results->hashes; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 AUTHOR |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Al Newkirk, C<< >> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 BUGS |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
209
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
210
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 SUPPORT |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
perldoc Win32::WMIC |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
You can also look for information at: |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=over 4 |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
L |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
L |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * CPAN Ratings |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
L |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item * Search CPAN |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
L |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=back |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Copyright 2009 Al Newkirk, all rights reserved. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
247
|
|
|
|
|
|
|
under the same terms as Perl itself. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
1; # End of Win32::WMIC |