ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Service functions
  • Overview
  • What is a service?
  • In which case should I use a service?
  • Differences between a service and an application
  • Creating a service with WINDEV
  • Creating a service
  • Developing a service
  • Programming a service
  • Generating a service
  • Creating the setup of a 32-bit or 64-bit Windows service
  • Creating the setup of a 32-bit or 64-bit Windows service
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Creating a service with WINDEV
Overview

What is a service?

A service is a specific type of application intended to be run without any user intervention.
A service can be configured to automatically start at the same time as the operating system and to run in background task.
Linux The services are also called daemons.

In which case should I use a service?

A service must be used to allow an application to respond to an external request at any time (read operation on a socket for example).
If the purpose of the service is to run a recurring task, we advise you to develop a standard application and to start this application in a scheduled task.

Differences between a service and an application

  • A service is always run under the identity of the same user (configured during the setup ) regardless of the user connected to the computer.
  • A service cannot directly interact with the connected user. A window can be opened by Open (to create a graphic process on images for example) but it must be systematically closed once the process is performed. There must be no call to a locking function (Info, Dialog, Edit...).
  • A service that uses an HFSQL database and, more generally, H* functions to access a database, must manage the conflicts (duplicates, integrity, modification, etc.) with HOnError. Otherwise, the service can be locked if a conflict occurs.
  • Windows A service can operate under the identity of the operating system itself.
  • Windows A service is not subject to the UAC or to the virtualization (from Windows Vista).
Creating a service with WINDEV

Creating a service

WINDEV allows you to create a service:
  • from a new project.
  • from an existing project.
To create a service from a new project:
  1. Click in the quick access buttons.
  2. The new element window appears: click "Project".
  3. The project creation wizard starts.
  4. Select the type of project to create: "Windows or Linux service". Go to the next step of the wizard.
  5. Select the service's operating system (Windows or Linux). Go to the next step of the wizard.
  6. Specify the runtime mode (32-bit or 64-bit).
  7. Then follow the different steps of wizard.
To create a service from an existing project, simply add a new project configuration: on the "Project" tab, in the "Project configuration" group, expand "New configuration". You can create:
  • a "Service" project configuration (32-bit or 64-bit).
  • a "Daemon Linux" project configuration (32-bit or 64-bit).
For more details, see Project configuration.
Developing a service

Programming a service

The created project includes two additional events to manage the service:
EventEffect
Running the service (called in loop)This event is the main event of the service. It is called in loop when the service is started (automatically at boot time or via a call to ServiceStart).
In most cases, this event will wait for an external request (by creating a socket and by calling SocketWaitForConnection for example) then it will trigger actions in response to this request.
For the services that run actions continuously, ServiceWait must be called for each iteration in this event in order to avoid consuming all the processor resources of the computer.
Remarks:
  • When code must be shared between a service and an application (a class for example), the runtime mode is returned by InServiceMode.
  • If SysDetectLockedSession is used in a service, call Multitask in the runtime code of the service to receive the Windows messages.

    Multitask(-1)
Stopping the serviceThis event is automatically called when the service receives a stop request (via a call to ServiceStop or when stopping the computer).
This event is called in a thread different from the "Running the service" event.
If the main event is locked on a resource (a socket for example), the "Service stop" event must destroy the resource in order to unlock the main event.
Remark: From the beginning of the process for stopping the service, the "Running the service" event is no longer called in a loop.

Remarks:
  • To edit the specific events of a service: on the "Home" tab, in the "General" group, expand and select "Project code".
  • Service-specific events are not taken into account by the telemetry: telemetry functions cannot be used in these events.
Generating a service
The service created can be generated according to its characteristics:
  • 32-bit Windows service.
  • 64-bit Windows service.
  • 32-bit Linux daemon.
  • 64-bit Linux daemon.
To generate the service, go to the "Project" tab, "Generation" group, and click "Generate". The generation wizard of the current configuration starts automatically.
The generation wizard:
  • of the Windows 32-bit or 64-bit service corresponds to the creation wizard of the executable. For more details, see Creating the executable.
  • of the Linux 32-bit or 64-bit service corresponds to the creation wizard of the Linux executable. For more details, see Creating the Linux executable.
Remark: The automatic download of WINDEV framework is not available for the services.
Creating the setup of a 32-bit or 64-bit Windows service

Creating the setup of a 32-bit or 64-bit Windows service

To create the setup of a Windows 32-bit or 64-bit service:
  1. Expand the generation icon in the quick access buttons and select "Create the setup procedure of the service".
  2. The first part of the wizard helps you generate the service (see previous paragraph). If the current configuration is a 32-bit service, the generation is performed in 32-bit. If the current configuration is a 64-bit service, the generation is performed in 64-bits.
  3. Choose the setup mode:
    • Stand-alone setup: this setup can be directly run on the computer where the service must be installed.
    • Push setup: this setup is used to deploy the service remotely on several computers connected in network.
  4. Specify the directory where the service will be installed by default. Go to the next step.
  5. Choose the files to install as well as the setup mode of the framework.
  6. In "Service description", specify:
    • The service name (will be used through programming in ServiceStart or ServiceInfo for example).
    • The full name of service (displayed in the "Name" column of service manager).
    • The service description (displayed in the "Description" column of the service manager).
    Go to the next step.
  7. Choose the parameters for starting the service:
    • Automatic (by default)
    • Manual
    • Disabled.
    Remark: The service can be started in delayed mode. This feature is available from Windows Vista.
  8. Select the management mode of errors if the service fails to start:
    • Ignore the errors.
    • Write the errors into the log of events.
    • Write the errors into the log of events and restart the computer with the last valid configuration.
    • Write the errors into the log of events and restart the computer.
  9. Specify the parameters of command line that must be given when starting the service. Go to the next step.
  10. Specify the parameters for managing the errors of the service.
    Several successive failures can be detected. For each one of them, select the management mode of errors among the following possibilities:
    • Perform no action.
    • Restart the service (by default).
    • Restart the computer.
    • Run a program.
  11. Go to the next step.
  12. Specify the user account under which the service will run:
    • Local system account (by default).
    • Local service account.
    • Network service account.
    • User account selected among the existing accounts.
    Remark: When the service is run with the local system account (by default), this service cannot access the network. If the events of the service must access the network, the network service account or domain user must necessarily be specified for its execution.
  13. Go to the next step.
  14. Choose the parameters for managing the accesses to the databases.
  15. Choose the additional modules: license, readme, optional tools, uninstaller.
  16. Depending on the selected setup mode (stand-alone or push), specify the requested options.
The wizard will generate the setup of the service.
Related Examples:
WD Service Training (WINDEV): WD Service
[ + ] This example presents the creation of a "service" application with WINDEV.

Summary of the example supplied with WINDEV:
A service is a resident program the can operate outside a Windows session (the application is started before the Windows "Login").
In most cases, this type of application has no interface (no window)
For example, a service can be a processing robot (automation of a batch process).
This example explains how a 'Service' program can be created in WINDEV.
The Service functions Unit examples (WINDEV): The Service functions
[ + ] Using the ServiceXXX functions to:
- list the services installed
- start a service
- stop a service
- pause and restart a service.
The service functions are available for the local computer and for a remote computer.
Note: To use the services of a remote computer, you must have the administrator rights on this computer.
Minimum version required
  • Version 11
Comments
Click [Add] to post a comment

Last update: 07/03/2023

Send a report | Local help