Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I wrote kinda daemon in Perl, portable one (not using any Win32 functions). I managed to write a WSH script to start it in the background (without visible console window), but what disappoints me is that on Win9x at least, when user logs off or reboots a box, she gets "Perl - please close this application first. OK/Cancel." dialog. I would like to avoid that warning completely. I need the script to terminate automatically on logoff, and have other reasons not to write it as a Windows Service. There are no such problems with Win2k and above (NT not tested). Could you please recommend any colution? I even don't mind adding invokations of Win32:: functions to it.. I think some kind of wrapper (small .exe that starts a specified commandline and kills child when Windows is about to be rebooted) should exist.. Thanks in advance for your answer.
  • Comment on "background" perl processes on Win9X - how to avoid that "Perl - please close this application" on Windows Reboot/Logoff?

Replies are listed 'Best First'.
Re: "background" perl processes on Win9X - how to avoid that "Perl - please close this application" on Windows Reboot/Logoff?
by kappa (Chaplain) on Apr 06, 2004 at 11:16 UTC
    Mm, give a try to Win32::Daemon for creating truly background processes.
Re: "background" perl processes on Win9X - how to avoid that "Perl - please close this application" on Windows Reboot/Logoff?
by muba (Priest) on Apr 06, 2004 at 09:51 UTC
    I'm not quite sure whether Windows sends kill-like signals to running processes. Maybe you could catch the signal and let the script close itsself.
      Already tried. No signals are sent (though tried to trap all possible)..
Re: "background" perl processes on Win9X - how to avoid that "Perl - please close this application" on Windows Reboot/Logoff?
by EdwardG (Vicar) on Apr 06, 2004 at 11:25 UTC
    You could write a C wrapper that responds to the message CTRL_LOGOFF_EVENT if running in a console or WM_QUERYENDSESSION and WM_ENDSESSION if running as a Window. I don't know how to write a callback in perl, maybe POE?
      In fact, I'm struggling with C wrapper now.. But it turns out that WM_QUERYENDSESSION is sent only to visible windows (only catching it on Win98+ allows to kill a child in time, without getting that "close application" dialog to appear); but I don't want any window to be visible (and an icon inside a tray is not acceptable either).. BTW, any hints how to make window to be visible from system POV, but invisible from user POV (e.g. offscreen windows or zero-sized windows?)
        From memory, the same messgae is sent to all windows on the system. You should beable to create an invisible window of 0x0 size using the CreateWindowEx API function. Your Perl App will need to add a message handler that responds to the appropriate messages.

        MSDN Article on Message Only Windows

        That doesn't sound right, I'm sure you can create an invisible window and still have it respond to WM_QUERYENDSESSION.

        Some Googling later...

        Message Only Windows

Re: "background" perl processes on Win9X - how to avoid that "Perl - please close this application" on Windows Reboot/Logoff?
by Anonymous Monk on Apr 07, 2004 at 10:01 UTC
    I found a solution with a help of my colleague - I need to use 'wperl' instead of 'perl' for running my scripts! So simple..
Re: "background" perl processes on Win9X - how to avoid that "Perl - please close this application" on Windows Reboot/Logoff?
by Anonymous Monk on Apr 06, 2004 at 09:05 UTC

    Not to be cruel... but I hope to hell by Win9x you mean Win98. Win95 is deprecated (as in Microsoft doesn't do anything for it anymore), and even Win98 is soon to follow. So, though this probably doesn't help you very much, I'd say upgrade to a newer version of Windows. *Relives the painful days of Windows 95*

      Yes, Win9x means Win98 and WinME. Unfortunately there is no luxury of ignoring Win98 and WinME for me.