in reply to perlsvc or firedaemon?
I posted the code here last year.
Update:I have noticed that Win32::Daemon appears not to be available for current perl versions.
For this app, since performance for this code is not an issue, you can use the external "sc" (Service Controller) command.
Here is the (untested) revised sub, that allows you to comment-out use Win32::Daemon:
sub MakeService{ my $ServiceName = shift or die "Service Name Not Specified\n"; my $ServiceDir = shift; my $ServiceCommandLine = shift; my %ServiceStatus; # See if registered in SERVICES if (Win32::Service::GetStatus("", $ServiceName, \%ServiceStatus)){ # Service Already Exists .. complain warn "**Service $ServiceName is Already defined as a SERVICE and +". $ServiceStatusCode{$ServiceStatus{CurrentState}} . "; Please Remove this service before adding**\n"; return 1; } #It may be in REGISTRY, but not registered as a service - check if (exists $Registry->{"LMachine/System/CurrentControlSet/Services/$ +ServiceName/"}) { warn "**Service $ServiceName is Already defined in Registry ". "; Please Remove this service before adding**\n"; return 1; } my %ServiceInfo = ( machine => '', name => "MRTG$ServiceName", display => "MRTG $ServiceName", path => '', user => '', pwd => '', description => "$ServiceName MRTG Service", parameters =>"%SystemRoot%\\system32\\srvany.exe", ); # if( Win32::Daemon::CreateService( \%ServiceInfo ) ) # { # print "Successfully added Service $ServiceInfo{name}.\n"; # } # else # { # print "Failed to add service $ServiceInfo{name}: " . Win32::F +ormatMessage( Win32::Daemon::GetLastError() ) . "\n"; # return 1; # } print "\t:$_" for qx|sc create $ServiceInfo{name} binpath=$ServiceIn +fo{parameters} DisplayName="$ServiceInfo{description}"|; $Registry->{"LMachine/System/CurrentControlSet/Services/$ServiceName/ +Parameters"}= { "/Application" => [$ServiceCommandLine ,"REG_SZ"], "/AppDirectory" => [$ServiceDir ,"REG_SZ"], } or die "Can not create services Parameter entry\n"; ## Need to actually START the new service ... print "Service $ServiceName Created. (Will AutoStart on reboot)\n"; print "To start it NOW, use the command:\n NET START MRTG$ServiceNa +me\n"; } ################################# sub DeleteThisService{ my $ServiceName = shift or die "No service specified to DELETE\n"; my $rslt = qx|sc delete $ServiceName|; #Win32::Daemon::DeleteService('', $ServiceName ); print "Service $ServiceName DELETED = $rslt ***\n"; }
..to maintain is to slowly feel your soul, sanity and sentience ebb away as you become one with the Evil.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perlsvc or firedaemon?
by Anonymous Monk on Feb 18, 2009 at 09:14 UTC | |
|
Re^2: perlsvc or firedaemon?
by smanicka (Scribe) on Feb 18, 2009 at 16:59 UTC | |
by NetWallah (Canon) on Feb 18, 2009 at 19:54 UTC |