smanicka has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I came across this example script for perlsvc offered as a part of pdk deployment tools.Since i havebeen trying to use that, i went ahead and created a .exe file for that code.I would like to know how i can go ahead with installing this as a service since it works if i say c:\> test.exe but if i say c:\> install test.exe ,it pops out as unknown command.net start also doesn't seem to work.would anyone be able to tell me how to perform the installations?

The code and the exe file are here http://www.esnips.com/web/perlstuff/ and the code is:

##################################################################### # # Example code for PerlSvc using Win32::GuiConsole # ##################################################################### #!Perl -w #-------------------------------------------------------------------- # Package Initialise #-------------------------------------------------------------------- package PerlSvc; use strict; use vars qw($CONSOLEDEBUG); #use Win32::GuiConsole 0.02; use Getopt::Long; #-------------------------------------------------------------------- # Console Init #-------------------------------------------------------------------- # ... some code to initialise buffers if we are in console debug mode +? $CONSOLEDEBUG = 1; #if($CONSOLEDEBUG) { Win32::GuiConsole::open_console('Perl Service Des +ktop Debugging Console'); } #-------------------------------------------------------- # The Config provides defaults for the service parameters # These can be overidden in the 'Install' procedure via # the --install command line option # All available options included for reference #-------------------------------------------------------- our %Config = (ServiceName => 'servicetest', DisplayName => 'A Test Service', StartType => 'auto', # auto, manual Interactive => 1, # boolean Description => 'Service with added console', UserName => undef, # will run as local system accou +nt Password => undef, StartNow => 1, # if set to false, service would + not run on install Dependencies => '', # ref to array of strings naming +service dependencies Parameters => '', # command line params passed to +exec on service start ); #-------------------------------------------------------- # setup when we're not running as service #-------------------------------------------------------- unless (defined &ContinueRun) { # we're not running as a service so use some defaults # and call the Interactive setup *ContinueRun = sub { sleep 1; return 1; }; *RunningAsService = sub { return 0 }; my $discard = RunningAsService(); Interactive(); } sub Interactive { # called when not started as a service Install(); Startup(); } #-------------------------------------------------------------- # service calls - Install, # Remove, # Help, # Pause, # Continue, # Startup #-------------------------------------------------------------- #-------------------------------------------------------------- # service Install #-------------------------------------------------------------- sub Install { my $help; Getopt::Long::GetOptions( 'service=s' => \$Config{ServiceName}, 'display=s' => \$Config{DisplayName}, 'starttype=s' => \$Config{StartType}, 'interactive=s' => \$Config{Interactive}, 'description=s' => \$Config{Description}, 'username=s' => \$Config{UserName}, 'password=s' => \$Config{Password}, 'startnow=s' => \$Config{StartNow}, 'dependencies=s' => \$Config{Dependencies}, 'parameters=s' => \$Config{Parameters}, 'help' => \$help, ); if($help) { &Help; } } #-------------------------------------------------------------- # service Remove #-------------------------------------------------------------- sub Remove { } #-------------------------------------------------------------- # service Help ---- accessible via command line #-------------------------------------------------------------- sub Help { # called when started with --help my $help = "Options when installing as service:\n\n"; $help .= '--install install as service' . "\n"; $help .= '--remove remove service' . "\n"; $help .= '--service the short service name' . "\n"; $help .= '--display the long service name' . "\n"; $help .= '--starttype auto | manual (default auto)' . "\n"; $help .= '--interactive 0 | 1 (allow interaction with desktop) ( +default 0 = false)' . "\n"; $help .= '--description a description of the service' . "\n"; $help .= '--username DOMAIN\USERNAME or .\USERNAME for local +user' . "\n"; $help .= '--password user password' . "\n"; $help .= '--startnow start service now' . "\n"; $help .= '--dependencies a list of services on which this depends +' . "\n"; $help .= '--parameters parameters to pass when service starts' +. "\n"; print $help; exit(0); } #-------------------------------------------------------------- # service Pause #-------------------------------------------------------------- sub Pause { print "I'm Pausing\n"; } #-------------------------------------------------------------- # service Continue #-------------------------------------------------------------- sub Continue { print "I'm resuming after a pause\n"; } #-------------------------------------------------------------- # service Startup #-------------------------------------------------------------- sub Startup { #----------------------------------------------------------------- +------- # service 'continue' loop #----------------------------------------------------------------- +------- while (ContinueRun(1)) { print "I'm a service and I'm running\n"; # do prog .......... print STDERR "And I also output errors\n"; } #----------------------------------------------------------------- +------- # clean up code for stopping service #----------------------------------------------------------------- +------- print "Thank you and goodnight\n"; } 1;
UPDATE I did get to install the service using test.exe --install . the output is "test service installed successfully.Test Service failed to start :The system cannot findthe path specified".I'm not sure if this is because of office security which doen't allow us access to the c:\> but the command prompt always points to a h:/>.Any suggestions would be welcome Thanks. -Sandhya

Replies are listed 'Best First'.
Re: perl svc, installation of the service
by Jenda (Abbot) on Feb 27, 2009 at 23:48 UTC

    Any chance the executable is on a mapped or substed drive? That is, is it on H: which points to \\some_server\share or something similar? The service manager attempts to start the service using the "LocalSystem" "account" ... it doesn't see your mapped drives. Make sure you store the executable on a local drive.