AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de servicios
  • 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
  • Services created with versions earlier than WINDEV 15
  • Services created with the "WD NT service" example
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Otros
Procedimientos almacenados
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 among the quick access buttons.
  2. The element creation 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 "Proyecto" pane, in the "Configuración del proyecto" group, expand "Nueva configuración". You can create:
  • a "Service" project configuration (32-bit or 64-bit).
  • a "Daemon Linux" project configuration (32-bit or 64-bit).
See Project configuration for more details.
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 event "Running the service".
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 event "Running the service" is no longer called in a loop.

Remark: To edit the specific events of a service: on the "Inicio" pane, in the "General" group, expand and select "Project code".
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" pane, "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. See Creating the executable for more details.
  • of the Linux 32-bit or 64-bit service corresponds to the creation wizard of the Linux executable. See Creating the Linux executable for more details.
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 among 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 by 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.
Services created with versions earlier than WINDEV 15

Services created with the "WD NT service" example

If the "WDService NT" example was used to create a service with a version earlier than WINDEV 15, this service can be converted into a WINDEV service as follows:
  1. Open the project in WINDEV (version 15 or later).
  2. Create a new "Windows service" configuration.
  3. In the "Initializing" process of the project, call the "InitService" procedure of your project.
  4. In the event "Running the service", call the "Service" procedure of your project.
  5. In the event "Stopping the service", call the "EndService" procedure of your project.
Versión mínima requerida
  • Versión 11
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 27/05/2022

Señalar un error o enviar una sugerencia | Ayuda local