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();