Class ServiceController() Foundation
Class function of the ServiceController class
This class implements the mechanism to control a service application. Basically it provides the interface to Start, Stop, Pause and Continue a service on service capable Windows platforms.
In addition, this class can be used to query the current status of a service. The method :queryAllServiceNames() returns an array of all installed services. By calling :getUpdatedControl(), an instance of this class is returned whose member variables :serviceType, :currentState, :controlsAccepted, :startType, :errorControl, :pathName, :startName and displayName contain status information of the service.
For technical basics please refer to the section Controling services.
Whenever an error occurs during a call to one of the methods :install(), :uninstall(), :start(), :stop(), :pause() and :continue() , the reason of the error can be retrieved with the method :getLastError(). Additionally the method :logError() is called.
This group lists class methods that change the behavior of a service. All methods of this group must be called after a controller for the service is registered with the class method :addController() but before the service is installed with :install().
After the control object is retrieved with the class method :getUpdatedControl() services status information is stored in instance variables of the returned object.
// This example implements the controller for the service MyService.
// (see the example for the ServiceApp() class)
// It is assumed that the executable of the service has the same
// location as this controller.
// With this controller it is possible to install, start, stop and to
// uninstall the service.
#include "service.ch"
CLASS Logger
EXPORTED:
INLINE METHOD write( cMsg )
? cMsg
RETURN SELF
ENDCLASS
PROCEDURE Main( cParam )
LOCAL cLocation, oLog, oCtrl, cServiceName
cServiceName := "MyService"
cLocation := CurDirectory() + "\"
oLog := Logger():new()
oCtrl := ServiceController()
oCtrl:addController( cServiceName , ;
"Alaska Software Service Sample" , ;
cLocation + cServiceName + ".exe" , ;
".\Frodo", "Hobbit", , ;
oLog )
DO CASE
CASE cParam == "i"
ServiceController():install( cServiceName )
CASE cParam == "s"
ServiceController():start( cServiceName )
CASE cParam == "x"
ServiceController():stop( cServiceName )
CASE cParam == "u"
ServiceController():uninstall( cServiceName )
ENDCASE
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.