in reply to Re^5: Turn a perl script into a Win32 Service
in thread Turn a perl script into a Win32 Service

The following works for me on XP:

  1. Install SrvAny with: instsrv "YourService" c:\the\Path\to\SrvAny.exe
  2. Use Regedit to add the following keys:
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SrvAny\Parameter +s] "Application"="\\perl\\bin\\wperl.exe \\test\\service.pl"

    Modify the paths to your wperl and script accordingly.

  3. Go into the Service Manager, double-click "YourService". Select the "Log-on" tab from the properties dialog and check the "Allow service to interact with desktop" option. Apply and save.
  4. This is my minimal service.pl:
    #! perl -slw use strict; use Win32; open LOG, '>', 'c:\test\service.log' or die; select LOG; $|++; Win32::MsgBox( 'From service.pl at ' . localtime, 0, "Service.pl" ); while( sleep 5 ) { Win32::MsgBox( 'From service.pl at ' . localtime, 0, "Service.pl" + ); print scalar localtime; } close LOG;

    It pops up a message box on startup and every 5 seconds thereafter. (And bloody annoying it is too :)

    It creates and writes to the log file.

YMMV on Vista.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^7: Turn a perl script into a Win32 Service
by Limbic~Region (Chancellor) on Oct 14, 2008 at 17:54 UTC
    BrowserUk,
    Thank you!

    There are two things here that I have not done (wperl vs perl and interact with desktop).

    Rather than try and apply those changes to my application, I will attempt to reproduce your results on Vista. If that doesn't work I will have isolated the problem to Vista. If it does, I will try it with my application. If it works then YAY. If it doesn't, I will have isolated my problem to my application. Either way, this is a huge help.

    Update: For the record, I did see the SrvAny trouble shooting guide indicating checking "interact with desktop" was necessary for the command prompt to be interactive but since my application doesn't read from STDIN or write to STDOUT/STDERR, I didn't think it applied.

    Cheers - L~R

Re^7: Turn a perl script into a Win32 Service
by Limbic~Region (Chancellor) on Oct 16, 2008 at 00:25 UTC
    BrowserUk,
    I assume you named "YourService" SrvAny given your registry path.

    The Bad News

    Your working XP example did not work on Vista

    The Good News

    I know why - Vista no longer supports interactive services

    Where I am at

    The ActiveState PerlSvc is not free but I will check with sales to find out if it works on Vista. I still have Win32::Daemon to explore but it will be hard for me to tell which problems are related to the module versus Vista :-(

    Cheers - L~R

      I know why - Vista no longer supports interactive services

      Good news that you know why. Crap that it doesn't. I wonder about the rational behind that, but what's new with MS decision making.

      I still have Win32::Daemon to explore but it will be hard for me to tell which problems are related to the module versus Vista :-(

      I will try (late tomorrow due to commitments), to work up a working Win32::Daemon sample. I thought that I had posted one here (at least) once before, but a casual google didn't turn it up.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        BrowserUk,
        I am working from one of the examples. I will let you know if I get it working (on Vista).

        Update: It looks like the issue is the combination of running perl as a service and trying to do Win32::OLE->new('Outlook.Application'). It hangs there for a while then dies with Win32::OLE->LastError = Win32::OLE(0.1709) error 0x80010001: "Call was rejected by callee" When I kill outlook from the process table, it still fails to get the inbox. I am trying to track these problems down now.

        Cheers - L~R