Running VDF programs as Windows Services
A Visual DataFlex program can be run as a Windows™ Service. This option allows the creation of programs, which in general will have no user-interface component, to run in the background and perform tasks in a continuous or scheduled manner.
Using the SrvAny Utility
Instructions for using this are available from Microsoft Support, while the software, originally provided as part of a Microsoft Resource Pack, is widely available to download (here is one example, but a quick Google will find many).
To summarise, the following steps have to be taken to create and customise any program (although our interest is obviously in VDF programs) to run as a Windows Service.
- Unzip the contents of the file srvany.zip into a suitable location. There are two executable files - instsrv.exe and srvany.exe - and a Windows™ Write file - srvany.wri - describing usage.
- At a Windows™ command prompt type the command:
{path-to-srvany}\instsrv.exe {YourServiceName} {path-to-srvany}\srvany.exe
- Using RegEdit.exe (or RegEdit32.exe), open the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{YourServiceName} key
- Within that create a new key called "Parameters"
- Within that Parameters key, create a new string value (REG_SZ) called "Application" and in it place the full path and filename of the VDF program to be executed
- Optionally, create within Parameters an "AppParameters" string value which will contain the parameters to be passed to the program
- Optionally, create within Parameters an "AppDirectory" string value which will contain the full path of the directory the application should run in
- Optionally, under the YourServiceName key create a string value "DisplayName" which will contain the display name of the service within the Control Panel Services applet
- Optionally, under the YourServiceName key create a string value "Description" which will contain the verbose description of the service within the Control Panel Services applet
- Optionally, under the YourServiceName key create a multi-string (REG_MULTI_SZ) value called "DependOnService" which will contain a list of the services that your service depends on having running (a local database service for instance)
- You should then be able to use the Control Panel Services applet to configure such things as the Start type (Automatic, Manual, Disabled), the account to run as and so on (these can also be done directly in the Registry, but it is both easier and safer to use the applet)
If configured to start automatically, your service will then run automatically when Windows is started.
With thanks to this article on VDF Guidance by Bob Worsley.