See http://www.roth.net/perl/Daemon/ for details and examples, particularly DirMon.pl and UpTimeMon.pl. These assume that a perl script is being run, but a minor modification to the examples allows a PAR .exe to be used:
Just need to change what is passed to CreateService in path and parameters:
Note also the extra quotes (") around $ScriptPath when running a .pl script
to allow it to run in a directory/folder with spaces in the name.Regards,
andy n
*****************************************************************
sub NewGetServiceConfig {use File::Basename;
my %Hash = (
name => 'X',
display => 'X service',
description => 'Runs a perl script executable (or PAR) as a service',
user => $Config{account_id},
password => $Config{account_password},
); my $ScriptPath = Win32::GetFullPathName($0);
my ($name,$dir,$ext) = fileparse($ScriptPath,'\.[^.]*$');
# ext is the last dot to the end if ( $ext eq '.pl' ) { # a perl script
$Hash{path} = $^X;
$Hash{parameters} = "\"$ScriptPath\" -l \"$Config{log_file}\" -t
$Config{timeout_value}";
}
else { # assume its an executable
$Hash{path} = $ScriptPath;
$Hash{parameters} = "-l \"$Config{log_file}\" -t
$Config{timeout_value}";
}return ( \%Hash ); }
sub Install {
my $ServiceConfig = NewGetServiceConfig(); if ( Win32::Daemon::CreateService($ServiceConfig) ) {
print "The $ServiceConfig->{display} was successfully installed.\n";
}
else {
print "Failed to add the $ServiceConfig->{display} service.\nError:
"
. GetError() . "\n";
}
}