Service Commands

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > NT Service commands >

Service Commands

SER. -  NT Service Commands

Previous Top Next


MiniRobotLanguage (MRL)

 

SER. Command

Manage NT Services

 

 

Intention

 

This command can be used to manage System Services. You can start and stop services.

You can install and uninstall a Service. And you can check if they are running or not.

To specify a service you will need to give the "service name" (sn). You can also specify the "display name" (dn), if you prefix it with "dn:". Please see

How to get the proper service name

on which choices you have to specify the service you want to deal with, in a way that it will really work for you, as expected.

 

Using the SER. - command, you can:

 

' Get the display-name of a service

SER.dn from sn|sn|pc-name[$$RES]

 

' Get the service-name from the display name (or a part of it)

SER.sn from dn|sn|pc[|$$RES]

 

' Get the "Run-State" of a service

' See if its running, stopped or whatever.

' Result in Textform.

SER.get run state|sn|pc|$$RES

 

' Get the "Run-State" of a service

' See if its running, stopped or whatever.

' Result is numeric.

SER.get run state numeric|sn|pc|$$RES

 

' Set the "Run-State" of a service

' Start it, Stop it etc.

SER.set run state|sn|pc|$$RST

 

' Stop service "All"

' This command will stop a service and - if needed -

' all "dependend services", which could prevent the service

' from beeign stopped.

' This is very useful, in case you want to unistall a service.

SER.stop service all|sn|pc[|$$RES]

 

' Get "Start-Mode" of a service

' For a list of possible "Start Modes"

' see here: !Service Commands

SER.get start mode|sn|pc|$$RET

 

' Set "Start Mode" of a service

' For a list of possible "Start Modes"

' see here: !Service Commands

SER.set start mode|sn|pc|sm[|$$RES]

 

' Get "Service Type", get a technical Info on the type of a service

' For a list of possible "Service Types"

' see here: !Service Commands

SER.get_service_type|sn|pc[|$$RET]

 

' Restart a service

' On a "Restart", a service is been stopped first

' and then started again.

'

SER.restart service|sn|pc[|$$RES]

 

' Install a service

SER.inst|Apple2|$$PAT|appl

 

' Uninstall a service

' internally also stops the service and all dependend services

' like a SER.stop service all|sn|pc

SER.uninstall|sn:Apple2      

 

 

 

Syntax

 

SER.P1|P2[|P3][|P4][|P5]

 

Details of the parameters depend on the used Subcommand, see below.

 

Parameter Explanation

 

P1 - Subcommand

 

'  Evaluate the display name of a service

 "dnf" or "dn from sn"

   Evaluate the "display name" of the service P2 (you must specify the service name)

  into variable P3.

 

  ' Examples:

  SER.dnf|sky

  SER.dnf|sky||$$RES

 

'  Evaluate the service name of a service

 "snf" or "sn from dn"

    Evaluate the "service name" of the service P2 (you must specify the display name)

    into variable P3.

 

' Examples:

  SER.snf|ya&AND:update

  SER.snf|ya&AND:update||$$RES

 

'  Evaluate the run state of a service with textual result

 "grs" or "get run state"

   Evaluate the "run state" of a specified service. You will get a result like

   "STOPPED" or "RUNNING". See a list of all states here:

    !Service Commands

' Examples:

 SER.grs|BDESVC

 SER.grs|BDESVC||$$RES

 

'  Evaluate the run state of a service with numerical result

 "grn" or "get run state numeric"

   Evaluate the "run state" of a specified service. You will get a numeric result,

    that is a number from 1 to 7. See a list of all numbers and their meanings here:

    !Service Commands

 

' Examples:

 SER.grn|BDESVC

 SER.grn|BDESVC||$$RES

 

' Stop a service, and stop all dependend services

 "sta" or "stop service all"

This command will stop (halt) a service.

If the service can not be stopped because there are

dependant services still running, they will also be stopped.

This is your command for safely stopping a service.

It will be called internally before uninstalling a service, using "uninstall",

to make sure the serivce is not running before Uninstallation.

 

SER.stop service all|sn|pc[|$$RES]

 

' Set the run state of a service, using a number (from list below)

 "srs" or "set_run_state"

This command will stop or start a service. Use the value 0 to start a service.

The command will take care internally if a service is disabled, and do whatever is needed to start or stop the service, yet keeping it disabled. Means: Using this command, you can start a service, even though if its disabled.

 

' Start a service

SER.srs|dn:ya&AND:update||0

' Stop a service

SER.srs|dn:update||1

 

 

' Evaluate the start mode of a service with numerical result

 "gsm" or "get start mode"

Evaluate the "Start Mode" of a specified service. You will get a numeric result,

    that is a number from 0 to 4. See a list of all numbers and their meanings here:

    !Service Commands

 

' Examples:

 SER.gsm|dn:ya&AND:update

 SER.gsm|dn:ya&AND:update||$$RES

 

 

' Set the start mode of a service with numerical result

 "ssm" or "set start mode"

  Set the "Start Mode" of a specified service. Use a numeric code, that is a number

  from 0 to 4 to specify the startmode.See a list of all numbers and their meanings here:

    !Service Commands. The operation may provide a result of 0 = failure, or 1 = success.

 

' Examples:

' Disable the service

 SER.ssm|dn:ya&AND:update||4

' Set startmode to AUTOMATIC START

' and get result of operation in Variable $$RES

 SER.ssm|dn:ya&AND:update||2|$$RES

 

 

' Evaluate the service type of a service with numerical result

 "gst" or "get service type"

 This command will provide you with a technical info on the selected service.

 The result will be in textual form. The example:

 

SER.gst|dn:ya&AND:update

will provide this: "SERVICE_WIN32_OWN_PROCESS".

See here for a list of possible results: !Service Commands.

 

' Restart a service

 "rst" or "restart service"

 This command will end and then restart the selected service.

 The result will be on TOS or in teh given variable. Here is an example:

 

SER.rst|dn:Netlog

SER.rst|dn:Netlog||$$RET

 

will restart the service like if you choose "restart" in the Menu of the service-management console. Using this command, you can restart a service, even if its disabled.

 

' Uninstall a service

 "uni" or "uninstall"

 

 This command will try to uninstall/kill the service with that name.

 It will first try to stop the service and all dependend services.

 This is a special feature. Use with caution and try usage first in a safe environment.

 

SER.uni|sn|pc-name

 

' Install a service

 "inst" or "install"

 

 This command will try to install the service with that name and executable.

 This is a special feature, and there is no warranty that this will work as expected.

 Use with caution and try usage first in a safe environment.

 You can remove a installed service using the above "Uninstall service".

 Therefore the command is somehow safe.

 The newly installed service does not start automatically, use the SER. command to set

  its proper parameters.

 

SER.inst|Service Display Name|Path of Service Exercutable|Service Name[|PC-Name]

 

P2 - Service-Name

 

P3 - Computer-Name or empty. In that case the local computer is used.

 

P4 - (optional) Variable for Result of Operation, if omitted

    TOS is used.

 

What happens in case of an error?

If the specified service is not found, the Error-Message "Error: No such service." is been placed on TOS.

In case there are other errors during the processing of the command, the return variable will be empty and the error-message is been placed on TOS.

The error-message will always be prefixed with an "Error: " to indicate that it is an error from the services-engine.

Here is an example for such an error-message:

"Error: The requested access to the services database was denied."

 

 

 

Example

 

'**********************************

' SER.

'**********************************

SER.dnf|clr_optim&ANDTHEN:v2.||$$RES

DBP.$$RES

SER.snf|yaho||$$RES

DBP.$$RES

SER.grs|yaho||$$RES

DBP.$$RES

END.

'**********************************

' Path to the service-executable

VAF.$$PAT=F:\00_MR\MR_Diff_Plus\release\Diff-Tool.exe

' Install as a service

SER.inst|Apple2|$$PAT|appl

MBX.!

' UNinstall the service

SER.uninstall|dn:Apple2

END.

 

'**********************************

' SER.

' Install-Service Sample Script

'**********************************

$$NAM=ComWdienst

$$PAT=?ws\CoinSvc.EXE

$$SRC=?path\CoinSvc.EXE

:again

IEF.$$PAT

 MBX.Bitte den vorhandenen Dienst erst Deinstallieren!

 GTO.enx

EIF.

NSI.$$NAM

 COP.$$SRC|$$PAT

 SER.install|ComWdienst|$$PAT|$$NAM

 SER.restart service|$$NAM

ELS.

 MBX.Es ist eine ältere Version des Dienstes installiert.$crlf$

 SER.stop service all|$$NAM

 SER.uninstall|$$NAM

 GTO.again

EIF.

:enx

ENR.

 

'**********************************

' SER.

' Uninstall-Service Sample Script

'**********************************

$$NAM=ComWdienst

$$PAT=?ws\CoinSvc.EXE

IEF.$$PAT

ISI.$$NAM  

 SER.stop service all|$$NAM

 SER.uninstall|$$NAM

 DEL.$$PAT

ELS.

 MBT.$$NAM gibts hier nicht als Dienst.

EIF.

ELS.

 MBT.Münzdienst ist hier nicht in $$PAT$crlf$installiert.

EIF.

ENR.

 

 

 

Remarks

 

-

 

 

 

Limitations:

In some cases the SER.-Command will lead to a program crash. In this case you can fix the problem using

 

     SER.srs|WEBZES_SERVER_NODE_01||0

    instead use

   EXC.?path\Service_start.bat|?path\

   WPT.#pid#

 

  Inside the batch file use

   net start servicename

   or

  sc config servicename start= auto

 

See also:

 

    !Service Commands

    ISC. - If Servic Command

    WSC. - Wait Service Command

    ISI. / NSI. - If Service Installed

    FES. - For Each Service