I'm poking around the bits and pieces of David Roths Win32::Daemon and attempting to learn how to use it to create and install services on Win32 machines. So, using some code from Tim Roth's Win32 Perl Scripting book, I've created the two small scripts below which I am attempting to get working correctly so I can modify it a piece at a time, and learn what all I can do with Win32::Daemon. The code is as follows:
use Win32::Daemon; open ( OUT, "C:\\Out.txt" ) || die ( "Unable to open file: $!" ); Win32::Daemon::StartService(); while ( SERVICE_STOPPED != ( $State = Win32::Daemon::State() ) ) { if ( SERVICE_START_PENDING == $State ) { print OUT "Starting Service\n"; Win32::Daemon::State( SERVICE_RUNNING ); } elsif ( SERVICE_PAUSE_PENDING == $State ) { print OUT "Pausing Service\n"; Win32::Daemon::State( SERVICE_PAUSED ); } elsif ( SERVICE_CONTINUE_PENDING == $State ) { print OUT "Resuming Service\n"; Win32::Daemon::State( SERVICE_RUNNING ); } elsif ( SERVICE_STOP_PENDING == $State ) { print OUT "Service Stopping"; Win32::Daemon::State( SERVICE_STOPPED ); } elsif ( SERVICE_RUNNING == $State ) { print OUT "Service Running"; } sleep(5); } Win32::Daemon::StopService();
I install the daemon with this:
#!/usr/bin/perl -w use Win32::Daemon; my %ServiceConfig = ( name => "TestService", display => "Testing a Perl Created Service", path => $^X, user => '', passwd => '', parameters => 'c:\Perl\scripts\TestService.pl', ); if ( Win32::Daemon::CreateService ( \%ServiceConfig ) ) { print "The '$ServiceConfig{display}' service"; print "was successfully installed.\n"; } else { print "Failed to add '$ServiceConfig{dislay}' service\n"; print "Error:"; print Win32::FormatMessage( Win32::Daemon::GetLastError() ), "\n"; }
And it installs happily. But when I open up Services, and choose "Start" I get: The service did not respond to the start or control request in a timely fashion

Any ideas?
Macphisto the I.T. Ninja

Everyone has their demons....

In reply to Win32::Daemon by Macphisto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.