ServiceControl Script Function Library

The ServiceControl script function library consists of two files:

  • ServiceControl.dll
  • ServiceControl.wdf

These script functions interact with the Windows Service Control Manager and therefore are compatible with Windows NT, Windows 2000, and Windows XP Professional. These functions are not supported on Windows 9x platforms.

 Download the ServiceControl.zip file from the Wonderware® Knowledge Base™.

  1. Unzip the ServiceControl.zip file.
  2. Copy the ServiceControl.dll and ServiceControl.wdf files and place them in your InTouch™ Install directory.
    • The functions will then be available from scripts when running WindowMaker.

 Library Functions

This library consists of five script functions:

  • WWServiceControl( ServiceName, Command )
  • WWGetServiceName( ServiceExeName )
  • WWGetServiceExeName( ServiceDisplayName )
  • WWGetServiceStatus( ServiceExeName )
  • WWServiceControlError( ErrorCode )


WWServiceControl( ServiceName, Command )

This function is used to stop, start or restart a service. The function requires two arguments. The first being the executable name of the service and the second the command.

Valid entries for the Command field are:

  • Stop
  • Start
  • Restart

Neither argument for this function or the others in this library is case sensitive.

The WWServiceControl function has a optional integer return value. The return value indicates success if equal to 0. Positive errors are Win32 codes. Negative errors code are generated by the ServiceControl DLL. It is recommended that the user execute the WWServiceControlError (See below) function following WWServiceControl. Use the return value from WWServiceControl as the  argument for the WWServiceControlError.  

Examples:

    ResultCode = WWServiceControl( “slssvc”, “stop” )

    ResultCode = WWServiceControl( SrvceMessageTag, CmdMessageTag )


WWGetServiceName( ServiceExeName )

This function is used to obtain the display name of a service given the executable name. The argument can be passed via a string or a memory message tag. The return value must be assigned to a memory message tag. The string return value will be the service display name, if successful, or an error string.

Example:

    ServiceDispName = WWGetServiceName( “slssvc” )


WWGetServiceExeName( ServiceDisplayName )

This function is used to obtain the executable name of a service given the display name. The display name is the name list in the services list. The argument can be passed via a string or a memory message tag. The return value must be assigned to a memory message tag. The string return value will be the service executable name, if successful, or an error string.

Example:

    DisplayName = “Wonderware Suitelink”

    ServiceExeName = WWGetServiceName( DisplayName )


WWGetServiceStatus( ServiceExeName )

This function is used to obtain the current status of a service given the executable name. The argument can be passed via a string or a memory message tag. The return value must be assigned to a memory message tag.

The possible return codes are:

  • SERVICE_CONTINUE_PENDING              ( The service continue is pending. ) 
  • SERVICE_PAUSE_PENDING                   ( The service pause is pending. )
  • SERVICE_PAUSED                              ( The service is paused. )
  • SERVICE_RUNNING                             ( The service is running. )
  • SERVICE_START_PENDING                   ( The service is starting. )
  • SERVICE_STOP_PENDING                     ( The service is stopping. )
  • SERVICE_STOPPED                             ( The service is not running. )
  • SERVICE_STATUS_UNKNOWN               ( The service status is unknown. Likely due to unknown ServiceExeName. ) 

When using this function in conditional statements it is important that the return value be checked against these case specific strings.


WWServiceControlError( ErrorCode )

This function returns the error message associated with the code specified in the argument. The return value is mandatory and must be a memory message tag. It is recommended that this function be executed following the WWServiceControl function to obtain the description associated with the return code.

Leave a Reply

Your email address will not be published. Required fields are marked *

30 − = 25