Although there might appear to be no practical difference between a service that is stopped and a service that is paused, the two states appear differently to the SCM. A stopped service is a service that is not running and must go through the entire service start procedure. A paused service, however, is still running but has had its functioning is suspended. Because of this, a paused service does not need to go through the entire service start procedure but needs a different procedure to resume functioning.
You must use the proper method to start a service that has been stopped or to resume a service that has been paused. The Win32_Service methods StartService and ResumeService should be used in the following situations:
The Resume AutoStart Services that are Paused VBScript sample restarts any auto-start services that have been paused.
The following VBScript code sample describes how to resume a paused service from instances of Win32_Service.
The following Perl code sample describes how to resume a paused service from instances of Win32_Service.
Example
Do not run below example code just to see what happens next. Many methods seriously affect your system. Always make sure you actually understand what the method and the code do.
$query = 'Select * From Win32_Service where Name="Spooler"'
Invoke-CimMethod -Query $query -MethodName ResumeService |
Add-Member -MemberType ScriptProperty -Name ReturnValueFriendly -Passthru -Value {
switch ([int]$this.ReturnValue)
{
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'}
default {"Unknown Error $_"}
}
}
To run this method on one or more remote systems, use New-CimSession
:
$session = New-CimSession -ComputerName $ComputerName -Credential $Credential
$query = 'Select * From Win32_Service where Name="Spooler"'
Invoke-CimMethod -Query $query -MethodName ResumeService -CimSession $session |
Add-Member -MemberType ScriptProperty -Name ReturnValueFriendly -Passthru -Value {
switch ([int]$this.ReturnValue)
{
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'}
default {"Unknown Error $_"}
}
}
Remove-CimSession -CimSession $session
Learn more about
Invoke-CimMethod
and invoking WMI methods.
Syntax
uint32 ResumeService();
Parameters
The method takes no arguments.
Return Value
Returns a value of type UInt32. Return values:
$returnValues = @{
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'
}
See Also
Additional methods implemented by Win32_Service:
Change()
Change() modifies a service.
ChangeStartMode()
ChangeStartMode() modifies the start mode of a service.
Create()
Delete()
Delete() deletes an existing service.
GetSecurityDescriptor()
GetSecurityDescriptor() returns the security descriptor that controls access to the service.
InterrogateService()
InterrogateService() requests that a service update its state to the service manager.
PauseService()
PauseService() attempts to place a service in the paused state.
SetSecurityDescriptor()
SetSecurityDescriptor() writes an updated version of the security descriptor that controls access to the service.
StartService()
StartService() attempts to place a service into the startup state.
StopService()
StopService() places a service in the stopped state.
UserControlService()
UserControlService() attempts to send a user-defined control code to a service.
Requirements
To use Win32_Service, the following requirements apply:
PowerShell
Get-CimInstance
was introduced with PowerShell Version 3.0, which in turn was introduced on clients with Windows 8 and on servers with Windows Server 2012.
If necessary, update Windows PowerShell to Windows PowerShell 5.1, or install PowerShell 7 side-by-side.
Operating System
Win32_Service was introduced on clients with Windows Vista and on servers with Windows Server 2008.
Namespace
Win32_Service lives in the Namespace Root/CIMV2. This is the default namespace. There is no need to use the -Namespace parameter in Get-CimInstance
.
Implementation
Win32_Service is implemented in CIMWin32.dll and defined in CIMWin32.mof. Both files are located in the folder C:\Windows\system32\wbem
:
explorer $env:windir\system32\wbem
notepad $env:windir\system32\wbem\CIMWin32.mof