Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling Win32 shutdown 1

Status
Not open for further replies.

obscurifer

Technical User
Apr 3, 2001
53
US
I want to write a program in Perl that sits and waits for Windows to shut down, then does something. I know that I have to use the Win32::Event module, and I have some code that I've written here.

========
use Win32::Event;

$manual = 0;
$initial = 0;
$name = "WM_QUERYENDSESSION";

$event = Win32::Event->new($manual,$initial,$name);
$event->wait();
open(OUTFILE, ">>c:/testout.txt") or die "Can't open file: $!";
print OUTFILE "Goodbye at " . scalar localtime() . "\n";
close OUTFILE;
========

If I set $name to some arbitrary event name, and then write another program that generates that event, this script will write to c:/testout.txt. If I run it as shown, I get nothing written to the file.

I suspect that WM_QUERYENDSESSION really talks to perl.exe (or wperl.exe) and not to my script, but I don't know that for sure.

So, the question is whether I can handle this event easily in Perl, or do I have to do something in C or some other compiled language?

TIA for all replies.
vrj
 
Hi,

Where did you get the defintion for WM_QUERYENDSESSION? Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884
 
I got it from <I>Programming Windows 95</I>, by Charles Petzold (ISBN: 1-55615-676-6), and it also exists in the Cygwin WINDOWSX.H file.

From the text of the book:
======
Windows begins sending every window procedure a WM_QUERYENDSESSION message when the user ends a Windows session. If any window procedure returns 0 from this message, the Windows session is not terminated. Here's how we handle WM_QUERYENDSESSION:

[C code deleted]
======

Maybe I need to return a 0?

vrj
 
Sorry, I wasn't clear - I meant:

Which perl script or module defines WM_QUERYENDSESSION? Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884
 
You know, that's a really good question. I wrote another script that uses Win32::Event->pulse() to send an arbitrarily named Windows event, and an appropriately configured script caught that event, but I'm guessing Windows doesn't pass events around by name.
 
I have asked the question of Chris Madsen, the author, let's see what we get back. The question I asked was:

Chris,

Sorry to bother you with a query.

Your module Win32::Event...

In the example below, from the documentation, what should the value of $name be? A string like this?

$manual = 0;
$initial = 0;
$name = &quot;WM_QUERYENDSESSION&quot;;

use Win32::Event;
$event = Win32::Event->new($manual,$initial,$name);
$event->wait();

Thanks for reading this far :) I know what a pain email support questions are....

Regards from the UK

Mike
Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884
 
&quot;Sorry, your message to chris_madsen@geocities.com cannot be delivered. This account is over quota.&quot;

Oh good... :-(

Ok.... Plan B Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884
 
Heh. Plan B is usually RTM again. In my first attempt at this, I wrote a message handler in C, and wrote some functionality in Perl. The C program launched the Perl program at the time of shutdown. I may have to revert back to that plan.

Thnaks for the help. If I do ever figure out the Perl-only solution, I'll let you know.

vrj
 
thanks.... I hate it when that happens Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top