#  InstallService.pl
#  Example 8.4:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script installs a Win32 service.
#
print "From the book 'Win32 Perl Scripting: The Administrator's Handbook' by Dave Roth\n\n";


use Win32::Daemon;
%ServiceConfig = (
    name    =>  'MyServiceName',
    display =>  'My Service Display Name',
    path    =>  $^X,
    user    =>  '',
    pwd     =>  '',
    parameters =>  'c:\scripts\MyService.pl',
    dependencies => [],
);
if( Win32::Daemon::CreateService( \%ServiceConfig ) )
{
    print "The '$ServiceConfig{display}' service was successfully installed.\n";
}
else
{
    print "Failed to add the '$ServiceConfig{display}' service.\n";
    print "Error: ";
    print Win32::FormatMessage( Win32::Daemon::GetLastError() ), "\n";
}

