PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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 is using a HFSQL database and more generally the H* functions to access a database must manage the conflicts (duplicates, integrity, modification, ...) via 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, select "File .. New .. Project". The wizard for project creation starts.To create a service from a new project:
  1. Click among the quick access buttons.
  2. Click "Project" in the wheel that is displayed. The window for creating a new element is displayed: click "Project".
  3. The wizard for project creation starts.
In one of the first screens, the wizard allows you to choose the generation mode of your project. All you have to do is select "Windows service" then the runtime platform (Windows or Linux) and follow the wizard.
By default, the project will allow you to generate Windows 32-bit services.
To create a service from an existing project, all you have to do is add a new project configuration ("Project .. Project configurations .. New configuration"). You have the ability to create: To create a service from an existing project, all you have to do is add a new project configuration: on the "Project" pane, in the "Project configuration" group, expand "New configuration". You have the ability to create:
  • a "Service" project configuration (32 bits).
  • a "64-bit service" project configuration.
  • a "Daemon Linux" project configuration.
See Project configuration for more details.
Developing a service

Programming a service

The created project includes two additional processes to manage the service:
ProcessEffect
Running the service (called in loop)This process is the main process 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 process is going to wait for an external request (by creating a socket and by calling SocketWaitForConnection for example) then it is going to trigger actions in response to this request.
For the services that run actions continuously, ServiceWait must be called for each iteration in this process in order to avoid consuming all the processor resources of the computer.
Notes:
  • When code must be shared between a service and an application (a class for example), the runtime mode is returned by InServiceMode.
  • Versions 20 and later
    If SysDetectLockedSession is used in a service, call Multitask in the runtime code of the service to receive the Windows messages.

    Multitask(-1)
    New in version 20
    If SysDetectLockedSession is used in a service, call Multitask in the runtime code of the service to receive the Windows messages.

    Multitask(-1)
    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 process is automatically called when the service receives a stop request (via a call to ServiceStop or when stopping the computer).
This process is called in a different thread than the "Service execution" process.
If the main process is locked on a resource (a socket for example), the "Service stop" process must destroy the resource in order to unlock the main process.
Note: From the beginning of the process for stopping the service, the "Service execution" process is no longer called in loop.
Note: To edit the specific processes of a service, select "Project .. Project code".Note: To edit the specific processes of a service: on the "Home" pane, in the "General" group, expand and select "Project code".
Generating a service
Three generation modes of a service are available:
  • Generate the Windows service (32 bits).
  • Generate the Windows service (64 bits).
  • Generate the Linux daemon.
These options are available in "Workshop .. Services". A generation wizard helps you generate the service.These options are available in the menu for generating the application.
A generation wizard helps you generate the service.
Note: If the proposed generation does not correspond to the current project configuration, WINDEV automatically proposes to create a new project configuration corresponding to the requested generation.
The generation wizard:
  • the Windows 32-bit or 64-bit service corresponds to the creation wizard of the executable. See Creating the executable for more details.
  • the Linux service corresponds to the creation wizard of the Linux executable. See Creating the Linux executable for more details.
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. Select "Workshop .. Services .. Create the setup procedure of service".Expand the generation icon among the quick access buttons and select "Create the setup procedure of service".
    Note: if the current configuration does not correspond to the configuration of the service, this option is available in the "Other generations" menu.
  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 bits. 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 plane.
  5. Choose the files to install as well as the setup mode of the framework.
  6. In the "Service description" screen, 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 service manager).
      Go to the next plane.
  7. Choose the parameters for starting the service:
    • Automatic (by default)
    • Manual
    • Disabled
      Note: 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 plane.
  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.
      Go to the next plane.
  11. 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.
      Note: When the service is run with the local system account (by default), this service cannot access the network. If the processes of the service must access the network, the network service account or domain user must necessarily be specified for its execution.
      Go to the next plane.
  12. Choose the parameters for managing the accesses to the databases.
  13. Choose the additional modules: license, readme, optional tools, uninstaller.
  14. 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 "Initialization" process of the project, call the "InitService" procedure of your project.
  4. In the "Service execution" process, call the "Service" procedure of your project.
  5. In the "Service stop" process, call the "EndService" procedure of your project.
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 required version
  • Version 11
Comments
Click [Add] to post a comment