in reply to Install a perl script as a Win NT/2000/XP service.
Okay, summary of steps based on reading a handful of web pages and dissecting jryan's Perl script at the top of this thread.
This should be deployable almost as is. About the only things you should need to change are references to where the Perl binary is located and which directory into which you drop all files from this example. Global change and replace should be sufficient on these strings:
Without further adieu:
#!/usr/bin/perl my $statim = time; open LOGFIL, ">>perlservicetest.log"; print LOGFIL "$statim perlservicetest START\n"; close LOGFIL; exit; __END__
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\perlservicetest\ +Parameters] "Application"="C:\\Perl\\bin\\perl.exe" "AppDirectory"="C:\\Steve\\Dev\\perlservice-perl" "AppParameters"="C:\\Steve\\Dev\\perlservice-perl\\perlservicetest.pl"
perlservicetest-install.bat :
@echo off echo ----------------------------------------------------------------- +-------------- echo Checking logfile contents echo ----------------------------------------------------------------- +-------------- type perlservicetest.log pause echo ----------------------------------------------------------------- +-------------- echo Checking service status echo ----------------------------------------------------------------- +-------------- sc qc "perlservicetest" pause echo ----------------------------------------------------------------- +-------------- echo Stopping old service echo ----------------------------------------------------------------- +-------------- net stop perlservicetest pause echo ----------------------------------------------------------------- +-------------- echo Removing old service echo ----------------------------------------------------------------- +-------------- instsrv perlservicetest remove sc qc "perlservicetest" pause echo ----------------------------------------------------------------- +-------------- echo Installing new service echo ----------------------------------------------------------------- +-------------- instsrv perlservicetest C:\Steve\Dev\perlservice-perl\srvany.exe sc qc "perlservicetest" pause echo ----------------------------------------------------------------- +-------------- echo Modifying new service parameters echo ----------------------------------------------------------------- +-------------- REM start /WAIT "Registry Update" perlservicetest.reg regedit /s C:\Steve\Dev\perlservice-perl\perlservicetest.reg pause echo ----------------------------------------------------------------- +-------------- echo Starting new service echo ----------------------------------------------------------------- +-------------- net start perlservicetest pause echo ----------------------------------------------------------------- +-------------- echo Checking logfile contents echo ----------------------------------------------------------------- +-------------- type perlservicetest.log echo ----------------------------------------------------------------- +--------------
Then, to remove the service:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\perlservicetest\ +Parameters] "Application"=- "AppDirectory"=- "AppParameters"=- [-HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\perlservicetest +\Parameters] [-HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\perlservicetest +]
@echo off echo ----------------------------------------------------------------- +-------------- echo Checking logfile contents echo ----------------------------------------------------------------- +-------------- type perlservicetest.log pause echo ----------------------------------------------------------------- +-------------- echo Checking service status echo ----------------------------------------------------------------- +-------------- sc qc "perlservicetest" pause echo ----------------------------------------------------------------- +-------------- echo Stopping old service echo ----------------------------------------------------------------- +-------------- net stop perlservicetest pause echo ----------------------------------------------------------------- +-------------- echo Removing old service echo ----------------------------------------------------------------- +-------------- instsrv perlservicetest remove sc qc "perlservicetest" pause echo ----------------------------------------------------------------- +-------------- echo Removing service parameters echo ----------------------------------------------------------------- +-------------- regedit /s C:\Steve\Dev\perlservice-perl\perlservicetest-delete.reg echo ----------------------------------------------------------------- +--------------
Once you have one that works, you can adjust individual components to customize it to your needs. Maybe you want instsrv.exe and srvany.exe to live somewhere common. Maybe you want to change the service name from perlservicetest . Maybe you want the Perl script to do more than write lines to a log file.
If the change you make doesn't give you the results you are looking for, roll back to the last one that worked, and keep chiseling away at it, back and forth, until you have molded it into your personal Windows Service masterpiece.
:-)
|
|---|