$cs.Service_Start
Description
Section titled “Description”Starts the named service and waits up to maxTimeout milliseconds for it to reach the Running state. Throws an exception if the service doesn’t exist, and also throws a timeout-related exception if it doesn’t reach Running within maxTimeout.
Syntax
Section titled “Syntax”$cs.Service_Start(string servicename, uint maxTimeout = 60000)
Parameters
Section titled “Parameters”servicename (String)
Section titled “servicename (String)”Name of the service to start.
maxTimeout (UInt32)
Section titled “maxTimeout (UInt32)”Maximum time to wait, in milliseconds, for the service to reach the Running state. Defaults to 60000 (60 seconds).
Return value
Section titled “Return value”None.
Example
Section titled “Example”Check the service exists before starting it:
if ($cs.Service_Exist("gupdate")){ $cs.Job_WriteLog("Starting gupdate service") $cs.Service_Start("gupdate")}Start a service right after installation and catch the exception if it fails or times out, without failing the whole install:
try{ $cs.Job_WriteLog("Starting MyAppService after install") $cs.Service_Start("MyAppService", 90000)}catch{ $cs.Job_WriteLog("MyAppService failed to start within the timeout: $($_.Exception.Message)")}Start a service with a shorter timeout when it’s expected to come up quickly, letting the exception propagate to fail the job if it doesn’t:
$cs.Job_WriteLog("Starting lightweight helper service")$cs.Service_Start("MyHelperService", 15000)