Change

Class method that modifies a service.

Class method that modifies a 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.

# define the arguments you want to submit to the method
# remove values that you do not want to submit
# make sure you replace values with meaningful content before running the code
# see section "Parameters" below for a description of each argument.
$arguments = @{
    DesktopInteract = [Boolean](12345)  # replace 12345 with a meaningful value
    DisplayName     = 'someText'  # replace 'someText' with meaningful text
    ErrorControl    = [UInt8](12345)  # replace 12345 with a meaningful value
    LoadOrderGroup  = 'someText'  # replace 'someText' with meaningful text
    LoadOrderGroupDependencies = 'someText'  # replace 'someText' with meaningful text
    PathName        = 'someText'  # replace 'someText' with meaningful text
    ServiceDependencies = 'someText'  # replace 'someText' with meaningful text
    ServiceType     = [UInt8](12345)  # replace 12345 with a meaningful value
    StartMode       = 'someText'  # replace 'someText' with meaningful text
    StartName       = 'someText'  # replace 'someText' with meaningful text
    StartPassword   = 'someText'  # replace 'someText' with meaningful text
}


# select the instance(s) for which you want to invoke the method
# you can use "Get-CimInstance -Query (ADD FILTER CLAUSE HERE!)" to safely play with filter clauses
# if you want to apply the method to ALL instances, remove "Where...." clause altogether.
$query = 'Select * From Win32_SystemDriver Where (ADD FILTER CLAUSE HERE!)'
Invoke-CimMethod -Query $query -Namespace Root/CIMV2 -MethodName Change -Arguments $arguments |
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:

$ComputerName = 'server12','server14'  # adjust to your server names
$Credential   = Get-Credential         # submit a user account with proper permissions

# define the arguments you want to submit to the method
# remove values that you do not want to submit
# make sure you replace values with meaningful content before running the code
# see section "Parameters" below for a description of each argument.
$arguments = @{
    DesktopInteract = [Boolean](12345)  # replace 12345 with a meaningful value
    DisplayName     = 'someText'  # replace 'someText' with meaningful text
    ErrorControl    = [UInt8](12345)  # replace 12345 with a meaningful value
    LoadOrderGroup  = 'someText'  # replace 'someText' with meaningful text
    LoadOrderGroupDependencies = 'someText'  # replace 'someText' with meaningful text
    PathName        = 'someText'  # replace 'someText' with meaningful text
    ServiceDependencies = 'someText'  # replace 'someText' with meaningful text
    ServiceType     = [UInt8](12345)  # replace 12345 with a meaningful value
    StartMode       = 'someText'  # replace 'someText' with meaningful text
    StartName       = 'someText'  # replace 'someText' with meaningful text
    StartPassword   = 'someText'  # replace 'someText' with meaningful text
}


$session = New-CimSession -ComputerName $ComputerName -Credential $Credential

# select the instance(s) for which you want to invoke the method
# you can use "Get-CimInstance -Query (ADD FILTER CLAUSE HERE!)" to safely play with filter clauses
$query = 'Select * From Win32_SystemDriver Where (ADD FILTER CLAUSE HERE!)'
Invoke-CimMethod -Query $query -Namespace Root/CIMV2 -MethodName Change -Arguments $arguments -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 Change(
  [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

Name Type Description
DesktopInteract Boolean  
DisplayName String  
ErrorControl UInt8  
LoadOrderGroup String  
LoadOrderGroupDependencies String  
PathName String  
ServiceDependencies String  
ServiceType UInt8  
StartMode String  
StartName String  
StartPassword String  

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'
}

Requirements

To use Win32_SystemDriver, 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_SystemDriver was introduced on clients with Windows Vista and on servers with Windows Server 2008.

Namespace

Win32_SystemDriver 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_SystemDriver 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