Win32_Service

Win32 Service
root/cimv2dynamickey : Name

Represents a service on a computer system running Windows.

On this page

Main example

List instances

# All instances of Win32_Service, with the main properties
Get-CimInstance -ClassName Win32_Service |
    Select-Object -Property Name, DisplayName, State, StartMode, StartName, ProcessId

Examples

Filter with WQL

# WQL filter evaluated by the provider: automatic services that are stopped
Get-CimInstance -ClassName Win32_Service -Filter "StartMode = 'Auto' AND State = 'Stopped'" |
    Select-Object -Property Name, DisplayName, State, StartMode, StartName, ProcessId

The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.

Query a remote computer (CIM session)

review before running
# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
    Get-CimInstance -CimSession $cimSession -ClassName Win32_Service |
        Select-Object -Property Name, DisplayName, State, StartMode, StartName, ProcessId
} finally {
    Remove-CimSession -CimSession $cimSession
}

WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.

Show the class structure

# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_Service
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

# Methods of the class
$cimClass.CimClassMethods |
    Select-Object -Property Name, ReturnType

Properties

26 of 26 properties
NameTypeAccessDescription
AcceptPausebooleanread

Indicates whether the service can be paused.

Code
# Value of AcceptPause for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, AcceptPause |
    Select-Object -Property Name, AcceptPause
AcceptStopbooleanread

Indicates whether the service can be stopped.

Code
# Value of AcceptStop for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, AcceptStop |
    Select-Object -Property Name, AcceptStop
Captionstringread

Short description of the service —a one-line string.

Code
# Value of Caption for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, Caption |
    Select-Object -Property Name, Caption
CheckPointuint32read

Value that the service increments periodically to report its progress during a long start, stop, pause, or continue operation. For example, the service increments this value as it completes each step of its initialization when it is starting up. The user interface program that invokes the operation on the service uses this value to track the progress of the service during a lengthy operation. This value is not valid and should be zero when the service does not have a start, stop, pause, or continue operation pending.

Code
# Value of CheckPoint for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, CheckPoint |
    Select-Object -Property Name, CheckPoint
CreationClassName keystringread

Name of the first concrete class to appear in the inheritance chain used in the creation of an instance. When used with the other key properties of the class, this property allows all instances of this class and its subclasses to be uniquely identified.

Code
# Value of CreationClassName for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, CreationClassName |
    Select-Object -Property Name, CreationClassName
DelayedAutoStartbooleanread

If True, the service is started after other auto-start services are started plus a short delay.

Windows Server 2012 R2, Windows 8.1, Windows Server 2012, Windows 8, Windows Server 2008 R2, Windows 7, Windows Server 2008 and Windows Vista: This property is not supported before Windows Server 2016 and Windows 10.

Code
# Value of DelayedAutoStart for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, DelayedAutoStart |
    Select-Object -Property Name, DelayedAutoStart
Descriptionstringread

Description of the object.

Code
# Value of Description for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, Description |
    Select-Object -Property Name, Description
DesktopInteractbooleanread

Indicates whether the service can create or communicate with windows on the desktop, and thus interact in some way with a user. Interactive services must run under the Local System account. Most services are not interactive; that is, they do not communicate with the user in any way.

Code
# Value of DesktopInteract for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, DesktopInteract |
    Select-Object -Property Name, DesktopInteract
DisplayNamestringread

Name of the service as viewed in the Services snap-in. This string has a maximum length of 256 characters. Note that the display name and the service name (which is stored in the registry) are not always the same. For example, the DHCP Client service has the service name Dhcp but the display name DHCP Client. The name is case-preserved in the Service Control Manager. However, DisplayName comparisons are always case-insensitive.

Constraint: Accepts the same value as the Name property.

Example: "Atdisk"

Code
# Value of DisplayName for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, DisplayName |
    Select-Object -Property Name, DisplayName
ErrorControlstringread

Severity of the error if this service fails to start during startup. The value indicates the action taken by the startup program if failure occurs. All errors are logged by the computer system.

Values (5)
ValueLabelDescription
IgnoreIgnoreUser is not notified.
NormalNormalUser is notified. Usually this will be a message box display notifying the user of the problem.
SevereSevereSystem is restarted with the last-known-good configuration.
CriticalCriticalSystem attempts to restart with a good configuration. If the service fails to start a second time, startup fails.
UnknownUnknownSeverity of the error is unknown.
Code
# Value of ErrorControl for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, ErrorControl |
    Select-Object -Property Name, ErrorControl
ExitCodeuint32read

Windows error code that defines errors encountered in starting or stopping the service. This property is set to ERROR_SERVICE_SPECIFIC_ERROR (1066) when the error is unique to the service represented by this class, and information about the error is available in the ServiceSpecificExitCode property. The service sets this value to NO_ERROR when running, and again upon normal termination.

Code
# Value of ExitCode for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, ExitCode |
    Select-Object -Property Name, ExitCode
InstallDatedatetimeread

Date object is installed. This property does not require a value to indicate that the object is installed.

Code
# Value of InstallDate for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_Service -Property Name, InstallDate |
    Select-Object -Property Name, InstallDate
Name keystringread

Unique identifier of the service that provides an indication of the functionality that is managed. This functionality is described in the Description property of the object.

Code
# Value of Name for each instance
Get-CimInstance -ClassName Win32_Service -Property Name |
    Select-Object -Property Name
PathNamestringread

Fully qualified path to the service binary file that implements the service.

Example: "\SystemRoot\System32\drivers\afd.sys"

Code
# Value of PathName for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, PathName |
    Select-Object -Property Name, PathName
ProcessIduint32read

Process identifier of the service.

Example: 324

Code
# Value of ProcessId for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, ProcessId |
    Select-Object -Property Name, ProcessId
ServiceSpecificExitCodeuint32read

Service-specific error code for errors that occur while the service is either starting or stopping. The exit codes are defined by the service represented by this class. This value is only set when the ExitCode property value is ERROR_SERVICE_SPECIFIC_ERROR (1066).

Code
# Value of ServiceSpecificExitCode for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, ServiceSpecificExitCode |
    Select-Object -Property Name, ServiceSpecificExitCode
ServiceTypestringread

Type of service provided to calling processes.

The values are:

Values (7)
ValueLabelDescription
Kernel DriverKernel Driver
File System DriverFile System Driver
AdapterAdapter
Recognizer DriverRecognizer Driver
Own ProcessOwn Process
Share ProcessShare Process
Interactive ProcessInteractive Process
Code
# Value of ServiceType for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, ServiceType |
    Select-Object -Property Name, ServiceType
Startedbooleanread

Indicates whether or not the service is started.

Code
# Value of Started for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, Started |
    Select-Object -Property Name, Started
StartModestringread

Start mode of the Windows base service.

Values (5)
ValueLabelDescription
BootBootDevice driver started by the operating system loader (valid only for driver services).
SystemSystemDevice driver started by the operating system initialization process. This value is valid only for driver services.
AutoAutoService to be started automatically by the service control manager during system startup. Auto services are started even if a user does not log on.
ManualManualService to be started by the Service Control Manager when a process calls the StartService method. These services do not start unless a user logs on and starts them.
DisabledDisabledService that cannot be started until its StartMode is changed to either Auto or Manual.
Code
# Value of StartMode for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, StartMode |
    Select-Object -Property Name, StartMode
StartNamestringread

Account name under which a service runs. Depending on the service type, the account name may be in the form of "DomainName\Username" or UPN format ("*Username@DomainName*"). The service process is logged by using one of these two forms when it runs. If the account belongs to the built-in domain, then ".\Username" can be specified. For kernel or system-level drivers, StartName contains the driver object name (that is, "\FileSystem\Rdr" or "\Driver\Xns") which the I/O system uses to load the device driver. Additionally, if NULL is specified, the driver runs with a default object name created by the I/O system based on the service name.

Example: "DWDOM\Admin"

Code
# Value of StartName for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, StartName |
    Select-Object -Property Name, StartName
Statestringread/write

Current state of the base service.

The values are:

Windows Server 2008 and Windows Vista: This property is read-only before Windows 7 and Windows Server 2008 R2.

Values (8)
ValueLabelDescription
StoppedStopped
Start PendingStart Pending
Stop PendingStop Pending
RunningRunning
Continue PendingContinue Pending
Pause PendingPause Pending
PausedPaused
UnknownUnknown
Code
# Value of State for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, State |
    Select-Object -Property Name, State

Warning. Changes the system: check with -WhatIf first. An elevated console is often required.

# Warning: changes State on the instance. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$setParameters = @{
    InputObject = $instance
    Property    = @{ State = 'Example' }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters
Statusstringread

Current status of the object. Various operational and nonoperational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future). Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is online, yet the managed element is neither "OK" nor in one of the other states.

The values are:

Values (12)
ValueLabelDescription
OKOK
ErrorError
DegradedDegraded
UnknownUnknown
Pred FailPred Fail
StartingStarting
StoppingStopping
ServiceService
StressedStressed
NonRecoverNonRecover
No ContactNo Contact
Lost CommLost Comm
Code
# Value of Status for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, Status |
    Select-Object -Property Name, Status
SystemCreationClassName keystringread

Type name of the system that hosts this service.

Code
# Value of SystemCreationClassName for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, SystemCreationClassName |
    Select-Object -Property Name, SystemCreationClassName
SystemName keystringread

Name of the system that hosts this service.

Code
# Value of SystemName for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, SystemName |
    Select-Object -Property Name, SystemName
TagIduint32read

Unique tag value for this service in the group. A value of 0 (zero) indicates that the service does not have a tag. A tag can be used to order service startup within a load order group by specifying a tag order vector in the registry located at:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ GroupOrderList

Tags are only evaluated for Kernel Driver and File System Driver start type services that have Boot or System start modes.

Code
# Value of TagId for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, TagId |
    Select-Object -Property Name, TagId
WaitHintuint32read

Estimated time required, in milliseconds, for a pending start, stop, pause, or continue operation. After the specified time has elapsed, the service makes its next call to the SetServiceStatus method with either an incremented CheckPoint value or a change in CurrentState. If the amount of time specified by WaitHint passes, and CheckPoint has not been incremented, or CurrentState has not changed, the service control manager or service control program assumes that an error has occurred.

Code
# Value of WaitHint for each instance
Get-CimInstance -ClassName Win32_Service -Property Name, WaitHint |
    Select-Object -Property Name, WaitHint

Methods

Change #

Modifies a service.

uint32 Change(
    [in] string DisplayName,
    [in] string PathName,
    [in] uint32 ServiceType,
    [in] uint32 ErrorControl,
    [in] string StartMode,
    [in] boolean DesktopInteract,
    [in] string StartName,
    [in] string StartPassword,
    [in] string LoadOrderGroup,
    [in] string[] LoadOrderGroupDependencies,
    [in] string[] ServiceDependencies
);

Parameters

ParameterTypeDirectionDescription
DisplayNamestringin

The display name of the service. This string has a maximum length of 256 characters. The name is case- preserved in the service control manager. *DisplayName* comparisons are always case-insensitive.

Constraints: Accepts the same value as the Name property.

Example, "Atdisk".

PathNamestringin

The fully qualified path to the executable file that implements the service, for example, "\SystemRoot\System32\drivers\afd.sys".

ServiceTypeuint32in

The type of services provided to processes that call them.

ErrorControluint32in

Severity of the error if this service fails to start during startup. The value indicates the action taken by the startup program if failure occurs. All errors are logged by the system.

StartModestringin

Start mode of the Windows base service. For more information, see the Remarks section.

Boot

Device driver started by the operating system loader. This value is valid only for driver services.

System

Device driver started by the operating system initialization process. This value is valid only for driver services.

Automatic

Service to be started automatically by the Service Control Manager during system startup.

Manual

Service to be started by the Service Control Manager when a process calls the StartService method.

Disabled

Service that can no longer be started.

DesktopInteractbooleanin

If True, the service can create or communicate with a window on the desktop.

StartNamestringin

Account name the service runs under. Depending on the service type, the account name may be in the form of DomainName\Username or .\Username. The service process will be logged using one of these two forms when it runs. If the account belongs to the built-in domain, .\Username can be specified. If NULL is specified, the service will be logged on as the LocalSystem account. For kernel or system-level drivers, *StartName* contains the driver object name (that is, \FileSystem\Rdr or \Driver\Xns) that the input and output (I/O) system uses to load the device driver. If NULL is specified, the driver runs with a default object name created by the I/O system based on the service name, for example, "DWDOM\Admin".

You also can use the User Principal Name (UPN) format to specify the StartName, for example, *Username@DomainName*.

StartPasswordstringin

Password to the account name specified by the *StartName* parameter. Specify NULL if you are not changing the password. Specify an empty string if the service has no password.

Note: When changing a service from a local system to a network, or from a network to a local system, *StartPassword* must be an empty string ("") and not NULL.

LoadOrderGroupstringin

Group name that it is associated with. Load order groups are contained in the system registry, and determine the sequence in which services are loaded into the operating system. If the pointer is NULL, or if it points to an empty string, the service does not belong to a group. For more information, see the Remarks section.

Dependencies between groups should be listed in the *LoadOrderGroupDependencies* parameter. Services in the load-ordering group list are started first, followed by services in groups not in the load-ordering group list, followed by services that do not belong to a group. The system registry has a list of load ordering groups located at:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ServiceGroupOrder

LoadOrderGroupDependenciesstring[]in

List of load-ordering groups that must start before this service starts. The array is doubly null-terminated. If the pointer is NULL, or if it points to an empty string, the service has no dependencies. Group names must be prefixed by the SC_GROUP_IDENTIFIER (defined in the Winsvc.h file) character to differentiate them from service names because services and service groups share the same namespace. Dependency on a group means that this service can run if at least one member of the group is running after an attempt to start all of the members of the group.

ServiceDependenciesstring[]in

List that contains the names of services that must start before this service starts. The array is doubly NULL-terminated. If the pointer is NULL, or if it points to an empty string, the service has no dependencies. Dependency on a service indicates that this service can run only if the service it depends on is running.

Return values

ValueLabelDescription
0SuccessThe request was accepted.
1Not SupportedThe request is not supported.
2Access DeniedThe user did not have the necessary access.
3Dependent Services RunningThe service cannot be stopped because other services that are running are dependent on it.
4Invalid Service ControlThe requested control code is not valid, or it is unacceptable to the service.
5Service Cannot Accept ControlThe requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6Service Not ActiveThe service has not been started.
7Service Request TimeoutThe service did not respond to the start request in a timely fashion.
8Unknown FailureUnknown failure when starting the service.
9Path Not FoundThe directory path to the service executable file was not found.
10Service Already RunningThe service is already running.
11Service Database LockedThe database to add a new service is locked.
12Service Dependency DeletedA dependency this service relies on has been removed from the system.
13Service Dependency FailureThe service failed to find the service needed from a dependent service.
14Service DisabledThe service has been disabled from the system.
15Service Logon FailedThe service does not have the correct authentication to run on the system.
16Service Marked For DeletionThis service is being removed from the system.
17Service No ThreadThe service has no execution thread.
18Status Circular DependencyThe service has circular dependencies when it starts.
19Status Duplicate NameA service is running under the same name.
20Status Invalid NameThe service name has invalid characters.
21Status Invalid ParameterInvalid parameters have been passed to the service.
22Status Invalid Service AccountThe account under which this service runs is either invalid or lacks the permissions to run the service.
23Status Service ExistsThe service exists in the database of services available from the system.
24Service Already PausedThe service is currently paused in the system.
25..4294967295Other

Call the Change method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'Change'
    Arguments   = @{
        DisplayName                = 'Example'
        PathName                   = 'Example'
        ServiceType                = 1
        ErrorControl               = 1
        StartMode                  = 'Manual'
        DesktopInteract            = $false
        StartName                  = 'Example'
        StartPassword              = 'Example'
        LoadOrderGroup             = 'Example'
        LoadOrderGroupDependencies = @('Example')
        ServiceDependencies        = @('Example')
    }
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'Success'
        1 = 'Not Supported'
        2 = 'Access Denied'
        3 = 'Dependent Services Running'
        4 = 'Invalid Service Control'
        5 = 'Service Cannot Accept Control'
        6 = 'Service Not Active'
        7 = 'Service Request Timeout'
        8 = 'Unknown Failure'
        9 = 'Path Not Found'
        10 = 'Service Already Running'
        11 = 'Service Database Locked'
        12 = 'Service Dependency Deleted'
        13 = 'Service Dependency Failure'
        14 = 'Service Disabled'
        15 = 'Service Logon Failed'
        16 = 'Service Marked For Deletion'
        17 = 'Service No Thread'
        18 = 'Status Circular Dependency'
        19 = 'Status Duplicate Name'
        20 = 'Status Invalid Name'
        21 = 'Status Invalid Parameter'
        22 = 'Status Invalid Service Account'
        23 = 'Status Service Exists'
        24 = 'Service Already Paused'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

ChangeStartMode #

Modifies the start mode of a service.

uint32 ChangeStartMode([in] string StartMode);

Parameters

ParameterTypeDirectionDescription
StartModestringin

Start mode of the Windows base service.

Return values

ValueLabelDescription
0SuccessThe request was accepted.
1Not SupportedThe request is not supported.
2Access DeniedThe user did not have the necessary access.
3Dependent Services RunningThe service cannot be stopped because other services that are running are dependent on it.
4Invalid Service ControlThe requested control code is not valid, or it is unacceptable to the service.
5Service Cannot Accept ControlThe requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6Service Not ActiveThe service has not been started.
7Service Request TimeoutThe service did not respond to the start request in a timely fashion.
8Unknown FailureUnknown failure when starting the service.
9Path Not FoundThe directory path to the service executable file was not found.
10Service Already RunningThe service is already running.
11Service Database LockedThe database to add a new service is locked.
12Service Dependency DeletedA dependency this service relies on has been removed from the system.
13Service Dependency FailureThe service failed to find the service needed from a dependent service.
14Service DisabledThe service has been disabled from the system.
15Service Logon FailedThe service does not have the correct authentication to run on the system.
16Service Marked For DeletionThis service is being removed from the system.
17Service No ThreadThe service has no execution thread.
18Status Circular DependencyThe service has circular dependencies when it starts.
19Status Duplicate NameA service is running under the same name.
20Status Invalid NameThe service name has invalid characters.
21Status Invalid ParameterInvalid parameters have been passed to the service.
22Status Invalid Service AccountThe account under which this service runs is either invalid or lacks the permissions to run the service.
23Status Service ExistsThe service exists in the database of services available from the system.
24Service Already PausedThe service is currently paused in the system.
25..4294967295Other

Call the ChangeStartMode method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'ChangeStartMode'
    Arguments   = @{ StartMode = 'Manual' }
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'Success'
        1 = 'Not Supported'
        2 = 'Access Denied'
        3 = 'Dependent Services Running'
        4 = 'Invalid Service Control'
        5 = 'Service Cannot Accept Control'
        6 = 'Service Not Active'
        7 = 'Service Request Timeout'
        8 = 'Unknown Failure'
        9 = 'Path Not Found'
        10 = 'Service Already Running'
        11 = 'Service Database Locked'
        12 = 'Service Dependency Deleted'
        13 = 'Service Dependency Failure'
        14 = 'Service Disabled'
        15 = 'Service Logon Failed'
        16 = 'Service Marked For Deletion'
        17 = 'Service No Thread'
        18 = 'Status Circular Dependency'
        19 = 'Status Duplicate Name'
        20 = 'Status Invalid Name'
        21 = 'Status Invalid Parameter'
        22 = 'Status Invalid Service Account'
        23 = 'Status Service Exists'
        24 = 'Service Already Paused'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

Create static#

Creates a new service.

uint32 Create(
    [in] string Name,
    [in] string DisplayName,
    [in] string PathName,
    [in] uint8 ServiceType,
    [in] uint8 ErrorControl,
    [in] string StartMode,
    [in] boolean DesktopInteract,
    [in] string StartName,
    [in] string StartPassword,
    [in] string LoadOrderGroup,
    [in] string[] LoadOrderGroupDependencies,
    [in] string[] ServiceDependencies
);

Parameters

ParameterTypeDirectionDescription
Namestringin

Name of the service to install to the Create method. The maximum string length is 256 characters. The Service Control Manager database preserves the case of the characters, but service name comparisons are always case-insensitive. Forward-slashes (/) and double back-slashes (\) are invalid service name characters.

DisplayNamestringin

Display name of the service. This string has a maximum length of 256 characters. The name is case-preserved in the Service Control Manager. *DisplayName* comparisons are always case-insensitive.

Constraints: Accepts the same value as the *Name* parameter.

Example: "Atdisk".

PathNamestringin

Fully qualified path to the executable file that implements the service.

Example: "\SystemRoot\System32\drivers\afd.sys".

ServiceTypeuint8in

Type of services provided to processes that call them.

ErrorControluint8in

Severity of the error if the Create method fails to start. The value indicates the action taken by the startup program if failure occurs. All errors are logged by the system.

0

User is not notified.

1

User is notified.

2

System is restarted with the last-known-good configuration.

3

System attempts to start with a good configuration.

StartModestringin

Start mode of the Windows base service.

Boot

Device driver started by the operating system loader. This value is valid only for driver services.

System

Device driver started by the operating system initialization process. This value is valid only for driver services.

Automatic

Service to be started automatically by the Service Control Manager during system startup.

Manual

Service to be started by the Service Control Manager when a process calls the StartService method.

Disabled

Service that can no longer be started.

DesktopInteractbooleanin

If true, the service can create or communicate with windows on the desktop.

StartNamestringin

Account name under which the service runs. Depending on the service type, the account name may be in the form of DomainName\Username or User Principal Name (UPN) format (Username@DomainName). The service process is logged using one of these two forms when it runs. If the account belongs to the built-in domain, .\Username can be specified. If NULL is specified, the service is logged on as the LocalSystem account. For a kernel or system-level drivers, *StartName* contains the driver object name (that is, \FileSystem\Rdr or \Driver\Xns) which the input and output (I/O) system uses to load the device driver. If NULL is specified, the driver runs with a default object name created by the I/O system based on the service name. Example: DWDOM\Admin.

StartPasswordstringin

Password to the account name specified by the *StartName* parameter. Specify NULL if you are not changing the password. Specify an empty string if the service has no password.

LoadOrderGroupstringin

Group name associated with the new service. Load order groups are contained in the registry, and determine the sequence in which services are loaded into the operating system. If the pointer is NULL or if it points to an empty string, the service does not belong to a group. Dependencies between groups should be listed in the *LoadOrderGroupDependencies* parameter. Services in the load-ordering group list are started first, followed by services in groups not in the load-ordering group list, followed by services that do not belong to a group. The registry has a list of load ordering groups located at:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ServiceGroupOrder

LoadOrderGroupDependenciesstring[]in

Array of load-ordering groups that must start before this service. Each item in the array is delimited by NULL and the list is terminated by two NULL values. In Visual Basic or script you can pass a vbArray. If the pointer is NULL or if it points to an empty string, the service has no dependencies. Group names must be prefixed by the SC_GROUP_IDENTIFIER (defined in the Winsvc.h file) character to differentiate it from a service name, because services and service groups share the same namespace. Dependency on a group means that this service can run if at least one member of the group is running after an attempt to start all of the members of the group.

ServiceDependenciesstring[]in

Array that contains names of services that must start before this service starts. Each item in the array is delimited by NULL and the list is terminated by two NULL values. In Visual Basic or script you can pass a vbArray. If the pointer is NULL, or if it points to an empty string, the service has no dependencies. Dependency on a service means that this service can only run if the service it depends on is running.

Return values

ValueLabelDescription
0The request was accepted.
1The request is not supported.
2The user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (**State** property of the Win32_BaseService class) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failure when starting the service.
9The directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.

Call the Create method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
$methodParameters = @{
    ClassName  = 'Win32_Service'
    MethodName = 'Create'
    Arguments  = @{
        Name                       = 'Example'
        DisplayName                = 'Example'
        PathName                   = 'Example'
        ServiceType                = 1
        ErrorControl               = 0
        StartMode                  = 'Example'
        DesktopInteract            = $false
        StartName                  = 'Example'
        StartPassword              = 'Example'
        LoadOrderGroup             = 'Example'
        LoadOrderGroupDependencies = @('Example')
        ServiceDependencies        = @('Example')
    }
    WhatIf     = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'The request was accepted'
        1 = 'The request is not supported'
        2 = 'The user did not have the necessary access'
        3 = 'The service cannot be stopped because other services that…'
        4 = 'The requested control code is not valid, or it is…'
        5 = 'The requested control code cannot be sent to the service…'
        6 = 'The service has not been started'
        7 = 'The service did not respond to the start request in a timely…'
        8 = 'Unknown failure when starting the service'
        9 = 'The directory path to the service executable file was not found'
        10 = 'The service is already running'
        11 = 'The database to add a new service is locked'
        12 = 'A dependency this service relies on has been removed from…'
        13 = 'The service failed to find the service needed from a…'
        14 = 'The service has been disabled from the system'
        15 = 'The service does not have the correct authentication to run…'
        16 = 'This service is being removed from the system'
        17 = 'The service has no execution thread'
        18 = 'The service has circular dependencies when it starts'
        19 = 'A service is running under the same name'
        20 = 'The service name has invalid characters'
        21 = 'Invalid parameters have been passed to the service'
        22 = 'The account under which this service runs is either invalid…'
        23 = 'The service exists in the database of services available…'
        24 = 'The service is currently paused in the system'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

Delete #

Deletes an existing service.

uint32 Delete();

Return values

ValueLabelDescription
0The request was accepted.
1The request is not supported.
2The user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failure when starting the service.
9The directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.

Call the Delete method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'Delete'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'The request was accepted'
        1 = 'The request is not supported'
        2 = 'The user did not have the necessary access'
        3 = 'The service cannot be stopped because other services that…'
        4 = 'The requested control code is not valid, or it is…'
        5 = 'The requested control code cannot be sent to the service…'
        6 = 'The service has not been started'
        7 = 'The service did not respond to the start request in a timely…'
        8 = 'Unknown failure when starting the service'
        9 = 'The directory path to the service executable file was not found'
        10 = 'The service is already running'
        11 = 'The database to add a new service is locked'
        12 = 'A dependency this service relies on has been removed from…'
        13 = 'The service failed to find the service needed from a…'
        14 = 'The service has been disabled from the system'
        15 = 'The service does not have the correct authentication to run…'
        16 = 'This service is being removed from the system'
        17 = 'The service has no execution thread'
        18 = 'The service has circular dependencies when it starts'
        19 = 'A service is running under the same name'
        20 = 'The service name has invalid characters'
        21 = 'Invalid parameters have been passed to the service'
        22 = 'The account under which this service runs is either invalid…'
        23 = 'The service exists in the database of services available…'
        24 = 'The service is currently paused in the system'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

GetSecurityDescriptor #

Returns the security descriptor that controls access to the service.

uint32 GetSecurityDescriptor([out] Win32_SecurityDescriptor Descriptor);

Parameters

ParameterTypeDirectionDescription
DescriptorWin32_SecurityDescriptorout

The security descriptor associated with the service.

Return values

ValueLabelDescription
0SuccessThe request was accepted.
2Access deniedThe user did not have the necessary access.
8Unknown failureUnknown failure when starting the service.
9Privilege missingThe directory path to the service executable file was not found.
21Invalid parameterInvalid parameters have been passed to the service.
22..4294967295Other

Call the GetSecurityDescriptor method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'GetSecurityDescriptor'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'Success'
        2 = 'Access denied'
        8 = 'Unknown failure'
        9 = 'Privilege missing'
        21 = 'Invalid parameter'
    }
    $returnValueName[[int]$result.ReturnValue]
    $result.Descriptor
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

InterrogateService #

Requests that a service update its state to the service manager.

uint32 InterrogateService();

Return values

ValueLabelDescription
0The request was accepted.
1The request is not supported.
2The user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failure when starting the service.
9The directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.

Call the InterrogateService method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'InterrogateService'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'The request was accepted'
        1 = 'The request is not supported'
        2 = 'The user did not have the necessary access'
        3 = 'The service cannot be stopped because other services that…'
        4 = 'The requested control code is not valid, or it is…'
        5 = 'The requested control code cannot be sent to the service…'
        6 = 'The service has not been started'
        7 = 'The service did not respond to the start request in a timely…'
        8 = 'Unknown failure when starting the service'
        9 = 'The directory path to the service executable file was not found'
        10 = 'The service is already running'
        11 = 'The database to add a new service is locked'
        12 = 'A dependency this service relies on has been removed from…'
        13 = 'The service failed to find the service needed from a…'
        14 = 'The service has been disabled from the system'
        15 = 'The service does not have the correct authentication to run…'
        16 = 'This service is being removed from the system'
        17 = 'The service has no execution thread'
        18 = 'The service has circular dependencies when it starts'
        19 = 'A service is running under the same name'
        20 = 'The service name has invalid characters'
        21 = 'Invalid parameters have been passed to the service'
        22 = 'The account under which this service runs is either invalid…'
        23 = 'The service exists in the database of services available…'
        24 = 'The service is currently paused in the system'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

PauseService #

Attempts to place a service in the paused state.

uint32 PauseService();

Return values

ValueLabelDescription
0The request was accepted.
1The request is not supported.
2The user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failure when starting the service.
9The directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.

Call the PauseService method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'PauseService'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'The request was accepted'
        1 = 'The request is not supported'
        2 = 'The user did not have the necessary access'
        3 = 'The service cannot be stopped because other services that…'
        4 = 'The requested control code is not valid, or it is…'
        5 = 'The requested control code cannot be sent to the service…'
        6 = 'The service has not been started'
        7 = 'The service did not respond to the start request in a timely…'
        8 = 'Unknown failure when starting the service'
        9 = 'The directory path to the service executable file was not found'
        10 = 'The service is already running'
        11 = 'The database to add a new service is locked'
        12 = 'A dependency this service relies on has been removed from…'
        13 = 'The service failed to find the service needed from a…'
        14 = 'The service has been disabled from the system'
        15 = 'The service does not have the correct authentication to run…'
        16 = 'This service is being removed from the system'
        17 = 'The service has no execution thread'
        18 = 'The service has circular dependencies when it starts'
        19 = 'A service is running under the same name'
        20 = 'The service name has invalid characters'
        21 = 'Invalid parameters have been passed to the service'
        22 = 'The account under which this service runs is either invalid…'
        23 = 'The service exists in the database of services available…'
        24 = 'The service is currently paused in the system'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

ResumeService #

Attempts to place a service in the resumed state.

uint32 ResumeService();

Return values

ValueLabelDescription
0The request was accepted.
1The request is not supported.
2The user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failure when starting the service.
9The directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.

Call the ResumeService method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'ResumeService'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'The request was accepted'
        1 = 'The request is not supported'
        2 = 'The user did not have the necessary access'
        3 = 'The service cannot be stopped because other services that…'
        4 = 'The requested control code is not valid, or it is…'
        5 = 'The requested control code cannot be sent to the service…'
        6 = 'The service has not been started'
        7 = 'The service did not respond to the start request in a timely…'
        8 = 'Unknown failure when starting the service'
        9 = 'The directory path to the service executable file was not found'
        10 = 'The service is already running'
        11 = 'The database to add a new service is locked'
        12 = 'A dependency this service relies on has been removed from…'
        13 = 'The service failed to find the service needed from a…'
        14 = 'The service has been disabled from the system'
        15 = 'The service does not have the correct authentication to run…'
        16 = 'This service is being removed from the system'
        17 = 'The service has no execution thread'
        18 = 'The service has circular dependencies when it starts'
        19 = 'A service is running under the same name'
        20 = 'The service name has invalid characters'
        21 = 'Invalid parameters have been passed to the service'
        22 = 'The account under which this service runs is either invalid…'
        23 = 'The service exists in the database of services available…'
        24 = 'The service is currently paused in the system'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

SetSecurityDescriptor #

Writes an updated version of the security descriptor that controls access to the service.

uint32 SetSecurityDescriptor([in] Win32_SecurityDescriptor Descriptor);

Parameters

ParameterTypeDirectionDescription
DescriptorWin32_SecurityDescriptorin

The security descriptor associated with the service.

Return values

ValueLabelDescription
0SuccessThe request was accepted.
1The request is not supported.
2Access deniedThe user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failureUnknown failure when starting the service.
9Privilege missingThe directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameterInvalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.
22..4294967295Other

Call the SetSecurityDescriptor method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'SetSecurityDescriptor'
    Arguments   = @{ Descriptor = $null }
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'Success'
        1 = 'The request is not supported'
        2 = 'Access denied'
        3 = 'The service cannot be stopped because other services that…'
        4 = 'The requested control code is not valid, or it is…'
        5 = 'The requested control code cannot be sent to the service…'
        6 = 'The service has not been started'
        7 = 'The service did not respond to the start request in a timely…'
        8 = 'Unknown failure'
        9 = 'Privilege missing'
        10 = 'The service is already running'
        11 = 'The database to add a new service is locked'
        12 = 'A dependency this service relies on has been removed from…'
        13 = 'The service failed to find the service needed from a…'
        14 = 'The service has been disabled from the system'
        15 = 'The service does not have the correct authentication to run…'
        16 = 'This service is being removed from the system'
        17 = 'The service has no execution thread'
        18 = 'The service has circular dependencies when it starts'
        19 = 'A service is running under the same name'
        20 = 'The service name has invalid characters'
        21 = 'Invalid parameter'
        22 = 'The account under which this service runs is either invalid…'
        23 = 'The service exists in the database of services available…'
        24 = 'The service is currently paused in the system'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

StartService #

Attempts to place a service into the startup state.

uint32 StartService();

Return values

ValueLabelDescription
0The request was accepted.
1The request is not supported.
2The user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failure when starting the service.
9The directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.

Call the StartService method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'StartService'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'The request was accepted'
        1 = 'The request is not supported'
        2 = 'The user did not have the necessary access'
        3 = 'The service cannot be stopped because other services that…'
        4 = 'The requested control code is not valid, or it is…'
        5 = 'The requested control code cannot be sent to the service…'
        6 = 'The service has not been started'
        7 = 'The service did not respond to the start request in a timely…'
        8 = 'Unknown failure when starting the service'
        9 = 'The directory path to the service executable file was not found'
        10 = 'The service is already running'
        11 = 'The database to add a new service is locked'
        12 = 'A dependency this service relies on has been removed from…'
        13 = 'The service failed to find the service needed from a…'
        14 = 'The service has been disabled from the system'
        15 = 'The service does not have the correct authentication to run…'
        16 = 'This service is being removed from the system'
        17 = 'The service has no execution thread'
        18 = 'The service has circular dependencies when it starts'
        19 = 'A service is running under the same name'
        20 = 'The service name has invalid characters'
        21 = 'Invalid parameters have been passed to the service'
        22 = 'The account under which this service runs is either invalid…'
        23 = 'The service exists in the database of services available…'
        24 = 'The service is currently paused in the system'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

StopService #

Places a service in the stopped state.

uint32 StopService();

Return values

ValueLabelDescription
0The request was accepted.
1The request is not supported.
2The user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failure when starting the service.
9The directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.

Call the StopService method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'StopService'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'The request was accepted'
        1 = 'The request is not supported'
        2 = 'The user did not have the necessary access'
        3 = 'The service cannot be stopped because other services that…'
        4 = 'The requested control code is not valid, or it is…'
        5 = 'The requested control code cannot be sent to the service…'
        6 = 'The service has not been started'
        7 = 'The service did not respond to the start request in a timely…'
        8 = 'Unknown failure when starting the service'
        9 = 'The directory path to the service executable file was not found'
        10 = 'The service is already running'
        11 = 'The database to add a new service is locked'
        12 = 'A dependency this service relies on has been removed from…'
        13 = 'The service failed to find the service needed from a…'
        14 = 'The service has been disabled from the system'
        15 = 'The service does not have the correct authentication to run…'
        16 = 'This service is being removed from the system'
        17 = 'The service has no execution thread'
        18 = 'The service has circular dependencies when it starts'
        19 = 'A service is running under the same name'
        20 = 'The service name has invalid characters'
        21 = 'Invalid parameters have been passed to the service'
        22 = 'The account under which this service runs is either invalid…'
        23 = 'The service exists in the database of services available…'
        24 = 'The service is currently paused in the system'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

UserControlService #

Attempts to send a user-defined control code to a service.

uint32 UserControlService([in] uint8 ControlCode);

Parameters

ParameterTypeDirectionDescription
ControlCodeuint8in

Specifies defined values (from 128 to 255) that provide control commands specific to a user.

Return values

ValueLabelDescription
0The request was accepted.
1The request is not supported.
2The user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (Win32_BaseService.**State** property) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failure when starting the service.
9The directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.

Call the UserControlService method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'UserControlService'
    Arguments   = @{ ControlCode = 0 }
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'The request was accepted'
        1 = 'The request is not supported'
        2 = 'The user did not have the necessary access'
        3 = 'The service cannot be stopped because other services that…'
        4 = 'The requested control code is not valid, or it is…'
        5 = 'The requested control code cannot be sent to the service…'
        6 = 'The service has not been started'
        7 = 'The service did not respond to the start request in a timely…'
        8 = 'Unknown failure when starting the service'
        9 = 'The directory path to the service executable file was not found'
        10 = 'The service is already running'
        11 = 'The database to add a new service is locked'
        12 = 'A dependency this service relies on has been removed from…'
        13 = 'The service failed to find the service needed from a…'
        14 = 'The service has been disabled from the system'
        15 = 'The service does not have the correct authentication to run…'
        16 = 'This service is being removed from the system'
        17 = 'The service has no execution thread'
        18 = 'The service has circular dependencies when it starts'
        19 = 'A service is running under the same name'
        20 = 'The service name has invalid characters'
        21 = 'Invalid parameters have been passed to the service'
        22 = 'The account under which this service runs is either invalid…'
        23 = 'The service exists in the database of services available…'
        24 = 'The service is currently paused in the system'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

Remarks

The Win32_Service class is derived from Win32_BaseService.

The way in which you manage a specific computer depends greatly on the role that computer plays. For example, you generally monitor different aspects of a DNS server than a DHCP server. Although no single property can tell you whether a particular computer is a database server, an e-mail server, or a multimedia server, you can often identify the role a computer plays by identifying the services installed on it.

In large organizations, only one of the major services (such as e-mail) is likely to be installed on a single computer. It would be unusual for a mail server to also perform as a server for Microsoft® Windows Media® technologies player files. Because of this, identifying a service installed on a computer can help identify the computer's role in the network. If the Microsoft® Exchange Server service is installed and running on a computer, it is generally safe to assume that this computer functions as a mail server.

You can use the WMI Win32_Service class to enumerate the services installed on a computer. In addition, you can use this class to determine whether those services are currently running and to return any other required information about that service and how it has been configured.

A service application conforms to the interface rules of the Service Control Manager (SCM), and can be started by a user automatically at system start through the Services control panel utility, or by an application that uses the service functions included in the Windows API. Services can start when there are no users logged on to the computer.

A user connecting from a remote computer must have the SC_MANAGER_CONNECT privilege enabled to be able to enumerate this class. For more information, see Service Security and Access Rights.

Inheritance

Superclass chain

  1. CIM_ManagedSystemElement
  2. CIM_LogicalElement
  3. CIM_Service
  4. Win32_BaseService
  5. Win32_Service

Known subclasses

No known subclass.

Requirements

Namespace
root/cimv2
Minimum client
Windows Vista
Minimum server
Windows Server 2008
Provider
CIMWin32
MOF file
CIMWin32.mof
DLL
CIMWin32.dll
Class qualifiers

Dynamic Provider("CIMWin32") SupportsUpdate UUID("{8502C4D9-5FBB-11D2-AAC1-006008C78BC7}") DisplayName("Services") AMENDMENT

Microsoft source

Source: Microsoft Learn

Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.