Main Site Contents Up Previous Next

Creating Windows Services

Cava Packager provides basic support for building and packaging Windows Services using the Win32::Daemon module.

If your version of Perl does not already have the Win32::Daemon module installed you can install using CPAN:

cpan Win32::Daemon

or the module is available from PPM repositories if your Perl supports PPM.

Cava Packager supports Win32::Daemon version 20110117 or later.

The minimum version of Windows for deployment is Windows XP or Windows Server 2003.


Cava Packager comes with an example service script that you may use to for the basis of your own service script if you wish. The example and supporting event log message resource can be found in the Cava Packager examples folder:

....\Cava Packager 2.0\examples\bin\
....\Cava Packager 2.0\examples\dll\winsvcmsg.dll

You can install, remove, start and stop the example service which contains examples of using the event log and responding to service control messages.

perl --install
perl --stop
perl --start
perl --remove

You can install multiple services using different service names

perl --install
perl --install --servicename="A Second Cava Service"
perl --remove
perl --remove --servicename="A Second Cava Service"

For a packaged executable called winservice.exe this becomes

...\App Directory\bin\winservice.exe --install
...\App Directory\bin\winservice.exe --install --servicename="A Second Cava Service"
...\App Directory\bin\winservice.exe --remove
...\App Directory\bin\winservice.exe --remove --servicename="A Second Cava Service"

Of course, you must be a user with administrative privileges to successfully install, remove, stop or start a service.

The service script as provided will automatically install correctly when run either as a Perl script or as part of a Cava Package. If the Cava Packager scan process detects the use of Win32::Daemon, the winsvcmsg.dll will also be packaged with your scripts.

When installing and running your script as a service using Perl during development, you should place a copy of winsvcmsg.dll in the location ../dll/winsvcmsg.dll relative to your service script. In fact the event logger will search for the dll in Cava::Packager::GetSharedLibraryPath() and ../dll/ is the default for this.

To create your Windows Service all you need to do is: callbacks provides hooks into the following functions / callbacks for you to write your own service code; also wraps the following eventlog functions

Contents Up Previous Next

Cava Packager Copyright © 2006-2012 Mark Dootson