I've got this perl/tk app that sits in the system tray (windows). When you lick on it small window opens and presents two options to the user via radio buttons.
What I'm trying to do is get the small window to open when the user is logging out/restarting or rebooting. This way they can select one of the radio buttons.
Here is the sample code I'm working with trying to catch a system event via wmi. What I'm having an issue with right now is identifying the class info to define the query. I think __Systemevents is the right area, but can't find helpful documentation.
use Win32::OLE qw(EVENTS);
use Win32::Console;
my $console = Win32::Console->new(STD_INPUT_HANDLE);
my $refWMI = Win32::OLE->GetObject('winMgmts:');
my $refSink = Win32::OLE->new ('WBemScripting.SWbemSink');
Win32::OLE->WithEvents($refSink,\&eventCallback);
my $strQuery = "SELECT * FROM __SessionEndingEventHandler "
. "WITHIN 10 WHERE TargetInstance ISA '\Win32_Service\'";
$refWMI->ExecNotificationQueryAsync($refSink, $StrQuery);
print "Waiting for Events ...\n";
my $continueLooping = 1;
while ($continueLooping) {
if ($console->GetEvents()!= 0){
my @cons = $console->Input();
if ($cons[1] != 0){
undef $countingLooping;
}
}
Win32::OLE->SpinMessageLoop();
Win32::Sleep(500);
}
$refSink->Cancel();
Win32::OLE->WithEvents($refSink);
undef $refSink;
undef $refWMI;
undef $console;
print "Finished.\n";
sub eventCallback()
{
my ($refSource,$refEventName,$refEvent,$refEvent,$refContext)
+= @_;
if ($refEventName eq "onObjectReady") {
print $refEvent->TargetInstance->{Name}
. " has "
. ($refEvent->TargetInstance->{Started}
? "started" : "stopped")
. "\n";
}
}
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.