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::FormatMessage( Win32::Daemon::GetLastError() ) . "\n"; # return 1; # } print "\t:$_" for qx|sc create $ServiceInfo{name} binpath=$ServiceInfo{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$ServiceName\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"; }