I am trying to port over some VBS WMI calls over to perl. I have been able to pull the user logon time thus far but am still having trouble pulling the user name.
Also, dumping the $ev variable hasnt provided me with any information to point me in the right place.
use DBI;
my $computer = ".";
my $dbh_connect = DBI->connect("dbi:WMI:$computer");
my $wmi_call = $dbh_connect->prepare(<<WQL);
Select * from Win32_LogonSession Where LogonType = 2 OR LogonType
+= 10
WQL
$wmi_call->execute();
while (defined (my $row = $wmi_call->fetchrow_arrayref())) {
my $ev = $row->[0];
$time = $ev->{StartTime};
$user = $ev->{Name};
}
print "User: $user LOGON TIME: $time;";
From reviewing the VBS it appears that the problem is where I am calling the
$wmi_call->execute();
When it was done in VBS the call was made like this
Set colList = objWMI.ExecQuery("Associators of " _
& "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} "
+_
& "Where AssocClass=Win32_LoggedOnUser Role=Dependent" )
But thus far I have been unable to port that execute over to perl
In reply to PERL WMI call
by Nar
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.