大网数据广告活动
Windows 系统接口

ChangeStartMode method of the Win32_Service class (CIMWin32 WMI Providers)

· 52CE 我爱测

Modifies the start mode of a Win32_Service.

The ChangeStartMode WMI class method modifies the start mode of a Win32_Service.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

uint32 ChangeStartMode(
  [in] string StartMode = Auto Start
);

Parameters

StartMode [in]

Start mode of the Windows base service.

Boot Start ("Boot")

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

System ("System")

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

Auto Start ("Automatic")

Service to be started automatically by the service control manager during system startup.

Demand Start ("Manual")

Service to be started by the service control manager when a process calls the StartService method.

Disabled ("Disabled")

Service that can no longer be started.

Return value

Returns one of the values listed in the following list or any other value to indicate an error. For additional error codes, see WMI Error Constants or WbemErrorEnum. For general HRESULT values, see System Error Codes.

Success

0

The request was accepted.

Not Supported

1

The request is not supported.

Access Denied

2

The user did not have the necessary access.

Dependent Services Running

3

The service cannot be stopped because other services that are running are dependent on it.

Invalid Service Control

4

The requested control code is not valid, or it is unacceptable to the service.

Service Cannot Accept Control

5

The 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.

Service Not Active

6

The service has not been started.

Service Request Timeout

7

The service did not respond to the start request in a timely fashion.

Unknown Failure

8

Unknown failure when starting the service.

Path Not Found

9

The directory path to the service executable file was not found.

Service Already Running

10

The service is already running.

Service Database Locked

11

The database to add a new service is locked.

Service Dependency Deleted

12

A dependency this service relies on has been removed from the system.

Service Dependency Failure

13

The service failed to find the service needed from a dependent service.

Service Disabled

14

The service has been disabled from the system.

Service Logon Failed

15

The service does not have the correct authentication to run on the system.

Service Marked For Deletion

16

This service is being removed from the system.

Service No Thread

17

The service has no execution thread.

Status Circular Dependency

18

The service has circular dependencies when it starts.

Status Duplicate Name

19

A service is running under the same name.

Status Invalid Name

20

The service name has invalid characters.

Status Invalid Parameter

21

Invalid parameters have been passed to the service.

Status Invalid Service Account

22

The account under which this service runs is either invalid or lacks the permissions to run the service.

Status Service Exists

23

The service exists in the database of services available from the system.

Service Already Paused

24

The service is currently paused in the system.

Other

25 4294967295

Examples

The following Change StartMode of a Service PowerShell sample changes the start mode of a service.

$wmi = get-wmiobject -class win32_service -namespace root\cimv2 -computername lisbon | 
where-object { $_.name -eq 'bits' } 
 
$rtn = $wmi.changestartmode("manual") 
if($rtn.returnvalue -eq 0) { "success" } 
ELSE 
  { " $($rtn.returnvalue) was reported" }

Requirements

Requirement Value
Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
Namespace Root\CIMV2
MOF CIMWin32.mof
DLL CIMWin32.dll

See also

Operating System Classes

Win32_Service

WMI Tasks: Services

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。