Hi,
OS: Windows 2000 SP2, Perl 5.6.1, 622
Problem:
I'm trying to use WMI to loop through events in Event Viewer's Application log. I am purposely trying to use WMI instead of Win32::EventLog. I'm trying to duplicate results from a vbscript I found on the web by using Win32::OLE. The program creates the object, but fails at the foreach loop. Once created $avents has a value of Win32::OLE=HASH(0x1ab5264), I don't know what this means exactly. The eventcode 1000 (event ID) does exist in the application log.
Sample Code:
use Win32::OLE qw (in);
$Computername = 'servername';
$Win32_Class ='Win32_NTLogEvent';
$Class = "WinMgmts://$Computername";
$Wmi = Win32::OLE->GetObject ($Class);
$if ($aevents = $Wmi->ExecQuery("SELECT * FROM $Win32_Class WHERE Logf
+ileName=Application
AND Eventcode=1000")) {
print "yeah...$aevents\n"; # prints yeah...Win32::OLE=HASH(0x1ab5264)
}
foreach $aevent (in($aevents)) { # Fails here.
print "$aevent{TimeGenerated}\n";
}
exit;
Any help would be much appreciated. Thank you.
Mitch
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.