Home |
The QtServiceController class allows you to control services from separate applications. More...
#include <QtServiceController>
The QtServiceController class allows you to control services from separate applications.
QtServiceController provides a collection of functions that lets you install and run a service controlling its execution, as well as query its status.
In order to run a service, the service must be installed in the system's service database using the install() function. The system will start the service depending on the specified StartupType; it can either be started during system startup, or when a process starts it manually.
Once a service is installed, the service can be run and controlled manually using the start(), stop(), pause(), resume() or sendCommand() functions. You can at any time query for the service's status using the isInstalled() and isRunning() functions, or you can query its properties using the serviceDescription(), serviceFilePath(), serviceName() and startupType() functions. For example:
MyService service; \\ which inherits QtService QString serviceFilePath; QtServiceController controller(service.serviceName()); if (controller.install(serviceFilePath)) controller.start() if (controller.isRunning()) QMessageBox::information(this, tr("Service Status"), tr("The %1 service is started").arg(controller.serviceName())); ... controller.stop(); controller.uninstall(); }
An instance of the service controller can only control one single service. To control several services within one application, you must create en equal number of service controllers.
The QtServiceController destructor neither stops nor uninstalls the associated service. To stop a service the stop() function must be called explicitly. To uninstall a service, you can use the uninstall() function.
See also QtServiceBase and QtService.
This enum describes when a service should be started.
Constant | Value | Description |
---|---|---|
QtServiceController::AutoStartup | 0 | The service is started during system startup. |
QtServiceController::ManualStartup | 1 | The service must be started manually by a process. |
Warning: The StartupType enum is ignored under UNIX-like systems. A service, or daemon, can only be started manually on such systems with current implementation.
See also startupType().
Creates a controller object for the service with the given name.
Destroys the service controller. This neither stops nor uninstalls the controlled service.
To stop a service the stop() function must be called explicitly. To uninstall a service, you can use the uninstall() function.
See also stop() and QtServiceController::uninstall().
Installs the service with the given serviceFilePath and returns true if the service is installed successfully; otherwise returns false.
On Windows service is installed in the system's service control manager with the given account and password.
On Unix service configuration is written to QSettings::SystemScope using "QtSoftware" as organization name. account and password arguments are ignored.
Warning: Due to the different implementations of how services (daemons) are installed on various UNIX-like systems, this method doesn't integrate the service into the system's startup scripts.
See also uninstall() and start().
Returns true if the service is installed; otherwise returns false.
On Windows it uses the system's service control manager.
On Unix it checks configuration written to QSettings::SystemScope using "QtSoftware" as organization name.
See also install().
Returns true if the service is running; otherwise returns false. A service must be installed before it can be run using a controller.
See also start() and isInstalled().
Requests the running service to pause. If the service's state is QtServiceBase::CanBeSuspended, the service will call the QtServiceBase::pause() implementation. The function does nothing if the service is not running.
Returns true if a running service was successfully paused; otherwise returns false.
See also resume(), QtServiceBase::pause(), and QtServiceBase::ServiceFlags.
Requests the running service to continue. If the service's state is QtServiceBase::CanBeSuspended, the service will call the QtServiceBase::resume() implementation. This function does nothing if the service is not running.
Returns true if a running service was successfully resumed; otherwise returns false.
See also pause(), QtServiceBase::resume(), and QtServiceBase::ServiceFlags.
Sends the user command code to the service. The service will call the QtServiceBase::processCommand() implementation. This function does nothing if the service is not running.
Returns true if the request was sent to a running service; otherwise returns false.
See also QtServiceBase::processCommand().
Returns the description of the controlled service.
See also install() and serviceName().
Returns the file path to the controlled service.
See also install() and serviceName().
Returns the name of the controlled service.
See also QtServiceController() and serviceDescription().
Starts the installed service passing the given arguments to the service. A service must be installed before a controller can run it.
Returns true if the service could be started; otherwise returns false.
See also install() and stop().
This is an overloaded function.
Starts the installed service without passing any arguments to the service.
Returns the startup type of the controlled service.
See also install() and serviceName().
Requests the running service to stop. The service will call the QtServiceBase::stop() implementation unless the service's state is QtServiceBase::CannotBeStopped. This function does nothing if the service is not running.
Returns true if a running service was successfully stopped; otherwise false.
See also start(), QtServiceBase::stop(), and QtServiceBase::ServiceFlags.
Uninstalls the service and returns true if successful; otherwise returns false.
On Windows service is uninstalled using the system's service control manager.
On Unix service configuration is cleared using QSettings::SystemScope with "QtSoftware" as organization name.
See also install().
Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt Solutions |