WMI.GetServiceState Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

Use the WMI.GetServiceState method to learn the current state of a service running on the local or remote computer that is specified by the WMI.ComputerName property.

Declaration

WMI.GetServiceState(ServiceName)

ServiceName [in]    Required    String    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

ServiceName

The service’s display name. For example, IIS Admin Service. This is the same value that is displayed in the Name column of the Administrative Tools | Services window and that is specified in the service’s Display name property. This parameter is case-insensitive.

Result Value

A string that specifies the service’s current state. Possible values are:

  • Continue Pending
  • Pause Pending
  • Paused
  • Running
  • Start Pending
  • Stop Pending
  • Stopped
  • Unknown

Example

The following example checks if the service current state is Stopped and, if so, restarts the computer.

JavaScript, JScript

// ...
if (WMI.GetServiceState("IIS Admin") == "Stopped")
  WMI.RestartComputer();
// ...

Python

# ...
if (WMI.GetServiceState("IIS Admin") == "Stopped"):
  WMI.RestartComputer()
# ...

VBScript

' ...
If WMI.GetServiceState("IIS Admin") = "Stopped" Then
  WMI.RestartComputer
End If
' ...

DelphiScript

// ...
if WMI.GetServiceState('IIS Admin') = 'Stopped' then
  WMI.RestartComputer;
// ...

C++Script, C#Script

// ...
if (WMI["GetServiceState"]("IIS Admin") == "Stopped")
  WMI["RestartComputer"]();
// ...

See Also

ComputerName Property
WaitForServiceState Method

Highlight search results