Create method of the Win32_BaseService class
The Create WMI class method creates a new service. The LoadOrderGroup parameter represents a grouping of system services defining execution dependencies. The services must be initiated in the order specified by the Load Order Group, as the services are dependent on each other. These dependent services require the presence of the antecedent services to function correctly.
This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.
Syntax
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
-
Name [in]
-
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.
-
DisplayName [in]
-
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".
-
PathName [in]
-
Fully qualified path to the executable file that implements the service.
Example: "\SystemRoot\System32\drivers\afd.sys".
-
ServiceType [in]
-
Type of services provided to processes that call them. The value is a bitmap.
-
Kernel Driver (1)
-
File System Driver (2)
-
Adapter (4)
-
Recognizer Driver (8)
-
Own Process (16)
-
Share Process (32)
-
256
-
Interactive Process
ErrorControl [in]
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.
Ignore (0)
User is not notified.
Normal (1)
User is notified.
Severe (2)
System is restarted with the last-known-good configuration.
Critical (3)
System attempts to start with a good configuration.
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 Start ("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.
DesktopInteract [in]
If true, the service can create or communicate with windows on the desktop.
StartName [in]
Account name under which the service runs. Depending on the service type, the account name may be in the form of "DomainName\Username". 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) 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. Example: DWDOM\Admin.
StartPassword [in]
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.
LoadOrderGroup [in]
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
LoadOrderGroupDependencies [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 members of the group.
ServiceDependencies [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 value
Returns one of the values listed in the following list or any other value to indicate an error.
-
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
Interactive process.
-
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 on which this service relies 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
There is no execution thread for the service.
-
Status Circular Dependency
-
18
There are circular dependencies when starting the service.
-
Status Duplicate Name
-
19
There is a service running under the same name.
-
Status Invalid Name
-
20
There are invalid characters in the name of the service.
-
Status Invalid Parameter
-
21
Invalid parameters have been passed to the service.
-
Status Invalid Service Account
-
22
The account which this service is to run under 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
Requirements
Requirement | Value |
---|---|
Minimum supported client |
Windows Vista |
Minimum supported server |
Windows Server 2008 |
Namespace |
Root\CIMV2 |
MOF |
|
DLL |
|