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(); #### #!/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"; }