Previous Next

INF AddService Directive

[DDInstall.Services]
 
AddService=ServiceName,[flags],service-install-section[,
             event-log-install-section[,[EventLogType][,EventName]]]
...
 
 

An AddService directive is used within an INF DDInstall.Services section or INF DefaultInstall.Services section. It specifies characteristics of the services associated with Windows 2000 or later drivers, such as how and when the services are loaded, and any dependencies on other underlying legacy drivers or services. Optionally, this directive also sets up event-logging services for the device.

This directive is not used in exclusively Windows 9x/Me INF files. It also is not used in INF files that install devices that do not require any drivers, such as modems or display monitors..

Entry Values

ServiceName
Specifies the name of the service to be installed. For a device, this value is usually a generic name for its driver, such as "sermouse," or some such name. This name must not be localized; it must be the same regardless of the system's local language.
flags
Specifies one or more (ORed) of the following system-defined flags, defined in setupapi.h, expressed as a hexadecimal value:
0x00000002 (SPSVCINST_ASSOCSERVICE)
Assign the named service as the PnP function driver (or legacy driver) for the device being installed by this INF file. Do not specify this flag when installing filter drivers or other driver components not directly associated with a device. Set this flag for only one driver for each INF DDIinstall.Services section.
0x00000008 (SPSVCINST_NOCLOBBER_DISPLAYNAME)
Do not overwrite the given service's (optional) friendly name if this service already exists in the system.
0x00000100 (SPSVCINST_NOCLOBBER_DESCRIPTION)
Do not overwrite the given service's (optional) description if this service already exists in the system.
0x00000010 (SPSVCINST_NOCLOBBER_STARTTYPE)
Do not overwrite the given service's start type if this named service already exists in the system.
0x00000020 (SPSVCINST_NOCLOBBER_ERRORCONTROL)
Do not overwrite the given service's error-control value if this named service already exists in the system.
0x00000040 (SPSVCINST_NOCLOBBER_LOADORDERGROUP)
Do not overwrite the given service's load-order-group value if this named service already exists in the system. INF files that install exclusively PnP devices and devices with WDM drivers should not set this flag.
0x00000080 (SPSVCINST_NOCLOBBER_DEPENDENCIES)
Do not overwrite the given service's dependencies list if this named service already exists in the system. INF files that install exclusively PnP devices and devices with WDM drivers should not set this flag.
0x00000001 (SPSVCINST_TAGTOFRONT)
Move the named service’s tag to the front of its group order list, thereby ensuring that it is loaded first within that group (unless a subsequently installed device with this INF specification displaces it). INF files that install exclusively PnP devices and devices with WDM drivers should not set this flag.
service-install-section
References an INF-writer-defined section that contains information for installing the named service for this device (or devices). For more information, see the following Comments section.
event-log-install-section
Optionally references an INF-writer-defined section in which event-logging services for this device (or devices) are set up.
EventLogType
Optionally specifies one of System, Security, or Application. If omitted, this defaults to System, which is almost always the appropriate value for the installation of device drivers. For example, an INF would specify Security only if the to-be-installed driver provides its own security support.
EventName
Optionally specifies a name to use for the event log. If omitted, this defaults to the given ServiceName.

Comments

The system-defined and case-insensitive extensions can be inserted into a DDInstall.Services section containing an AddService directive in cross-OS and/or cross-platform INF files to specify platform-specific or OS-specific installations. For information about how to use the system-defined .nt, .ntx86, and .ntia64 extensions, see Creating INF Files for Multiple Platforms and Operating Systems.

Each INF-writer-created section name must be unique within the INF and must follow the general rules for defining section names. These rules are described in General Syntax Rules for INF Files.

An AddService directive must reference a named service-install-section elsewhere in the INF file. Each such section has the following form:

[service-install-section]
 

[DisplayName=name]
[Description=description-string]
ServiceType=type-code
StartType=start-code
ErrorControl=error-control-level
ServiceBinary=path-to-service
[StartName=driver-object-name]
[AddReg=add-registry-section[, add-registry-section] ...]
[DelReg=del-registry-section[, del-registry-section] ...]
[BitReg=bit-registry-section[,bit-registry-section] ...]
[LoadOrderGroup=load-order-group-name]
[Dependencies=depend-on-item-name[,depend-on-item-name]
[Security="security-descriptor-string"]...]

Each service-install-section must have at least the ServiceType, StartType, ErrorControl, and ServiceBinary entries as shown here, but the remaining entries are optional.

Service-Install Section Entries and Values

DisplayName=name
Specifies a friendly name for the service/driver, usually, for ease of localization, expressed as a %strkey% token defined in a Strings section of the INF file.
Description=description-string
Optionally specifies a string that describes the service, usually expressed as a %strkey% token defined in a Strings section of the INF file.

This string gives the user more information about the service than the DisplayName. For example, the DisplayName might be something like "DHCP Client" and the Description might be something like "Manages network configuration by registering and updating IP addresses and DNS names".

The description-string should be long enough to be descriptive but not so long as to be awkward. If a description-string contains any %strkey% tokens, each token can represent a maximum of 511 characters. The total string, after any string token substitutions, should be no longer than 1024 characters. Most strings will be shorter.

ServiceType=type-code
In any INF that installs support for one or more devices, the type-code specification must be 1 or 0x00000001 (that is, equivalent to SERVICE_KERNEL_DRIVER).

A device-dedicated application supplied when installing the device would be classified as either of SERVICE_WIN32_OWN_PROCESS (specified as 10 or 0x00000010 in the INF) or SERVICE_WIN32_SHARE_PROCESS (specified as 20 or 0x00000020 in the INF).

A highest level network driver, such as a redirector, or a file system would be classified as SERVICE_FILE_SYSTEM_DRIVER by specifying 2 or 0x00000002 in its INF.

The SERVICE_xxxx constants are defined in wdm.h and ntddk.h.

StartType=start-code
Specifies when to start the driver as one of the following numerical values, expressed either in decimal or, as shown here, in hexadecimal notation.
0x0 (SERVICE_BOOT_START)
Indicates a driver started by the operating system loader.

This value must be used for drivers of devices required for loading the operating system.

0x1 (SERVICE_SYSTEM_START)
Indicates a driver started during OS initialization.

This value should be used by PnP drivers that do device detection during initialization but are not required to load the system.

For example, a PnP driver that also can detect a legacy device should specify this value in its INF so that its DriverEntry routine will be called to find the legacy device, even if that device cannot be enumerated by the PnP Manager.

0x2 (SERVICE_AUTO_START)
Indicates a driver started by the Service Control Manager during system startup.

This value should never be used in the INF files for WDM or PnP device drivers.

0x3 (SERVICE_DEMAND_START)
Indicates a driver started on demand, either by the PnP Manager when the corresponding device is enumerated or possibly by the Service Control Manager in response to an explicit user demand for a non-PnP device.

This value should be used in the INF files for all WDM drivers of devices that are not required to load the system and for all PnP device drivers that are neither required to load the system nor engaged in device detection.

0x4 (SERVICE_DISABLED)
Indicates a driver that cannot be started.

This value can be used to temporarily disable the driver services for a device, but a device/driver cannot be installed if this value is specified in the service-install section of its INF file.

For additional information about StartType, see Specifying Driver Load Order.

ErrorControl=error-control-level
Specifies the level of error control as one of the following numerical values, expressed either in decimal or, as shown here, in hexadecimal notation.
0x0 (SERVICE_ERROR_IGNORE)
If the driver fails to load or initialize, proceed with system startup and do not display a warning to the user.
0x1 (SERVICE_ERROR_NORMAL)
If the driver fails to load or initialize its device, system startup should proceed but display a warning to the user.
0x2 (SERVICE_ERROR_SEVERE)
If the driver fails to load, system startup should switch to the registry's LastKnownGood control set and continue system startup, even if the driver again indicates a loading or device/driver initialization error.
0x3 (SERVICE_ERROR_CRITICAL)
If the driver fails to load and system startup is not using the registry's LastKnownGood control set, switch to LastKnownGood and try again. If startup still fails when using LastKnownGood, run a bug-check routine. (Only devices/drivers necessary for the system to boot specify this value in their INF files.)
ServiceBinary=path-to-service
Specifies the path to the binary for the service, expressed as %dirid%\filename.

The dirid number is either a custom directory identifier or one of the system-defined directory identifiers described in Using Dirids. The given filename specifies a file already transferred (see the INF CopyFiles directive) from the source distribution media to that directory on the target machine.

StartName=driver-object-name
This optional entry specifies the name of the driver object representing this device/driver. If type-code specifies 1 or 2 (SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER), this name is the driver object name that the I/O Manager uses to load the driver.
AddReg=add-registry-section[, add-registry-section] ...
References one or more INF-writer-defined add-registry-sections in which any registry information pertinent to the newly installed services is set up. This directive is rarely used in a service-install-section. An HKR specification in such an add-registry-section designates the HKLM\System\CurrentControlSet\Services\ServiceName registry key. For more information, see INF AddReg Directive.
DelReg=del-registry-section[, del-registry-section] ...
References one or more INF-writer-defined del-registry-sections in which pertinent registry information for an already installed services is removed. An HKR specification in such a del-registry-section designates the HKLM\System\CurrentControlSet\Services\ServiceName registry key. This directive is almost never used in a service-install-section, but it might be used in an INF that "updates" the registry for a previous installation of the same device/driver services. For more information see INF DelReg Directive.
BitReg=bit-registry-section[,bit-registry-section] ...
Is valid in a service-install-section but almost never used. An HKR specification in such a bit-registry-section also designates the HKLM\System\CurrentControlSet\Services\ServiceName registry key.
LoadOrderGroup=load-order-group-name
This optional entry identifies the load order group of which this driver is a member. It can be one of the "standard" load order groups, such as SCSI class or NDIS, defined by previous versions of Windows NT®.

In general, this entry is unnecessary for devices with WDM drivers or for exclusively PnP devices, unless there are legacy dependencies on such a group. However, this entry can be useful if device detection is supported by loading a group of drivers in a particular order.

For additional information about LoadOrderGroup, see Specifying Driver Load Order.

Dependencies=depend-on-item-name[,depend-on-item-name]...
Each depend-on-item-name item in a dependencies list specifies the name of a service or load-order group on which the device/driver depends.

If the depend-on-item-name specifies a service, the service that must be running before this driver is started. For example, the INF for the system-supplied Win32 TCP/IP print services depends on the support of the underlying (kernel-mode) TCP/IP transport stack. Consequently, the INF for the TCP/IP print services specifies this entry as Dependencies =TCPIP.

A depend-on-item-name can specify a load order group on which this device/driver depends. Such a driver is started only if at least one member of the specified group has been started. Precede the group name with a plus sign (+). For example, the system RAS services INF might have an entry like Dependencies = +NetBIOSGroup,RpcSS, which lists both a load-order group and a service.

Security="security-descriptor-string"
Specifies a security descriptor, to be applied to the service. This security descriptor specifies the permissions required to perform such operations as starting, stopping, and configuring the service. The security-descriptor-string value is a string with tokens to indicate the DACL (D:) security component. See Platform SDK documentation for information about the format of security descriptor strings.

For more information about specifying security descriptors, see Creating Secure Device Installations.

The operating system loads drivers according to the service-install-section StartType value, as follows:

  1. During the system boot start phase, the OS loads all 0x0 (SERVICE_BOOT_START) drivers.
  2. During the system start phase, the OS first loads all WDM and PnP drivers for which the PnP Manager finds devnodes in the registry ..\Enum tree (whether their INF files say 0x01 for SERVICE_SYSTEM_START or 0x03 for SERVICE_DEMAND_START).Then the OS loads all remaining SERVICE_SYSTEM_START drivers.
  3. During the system auto-start phase, the OS loads all remaining SERVICE_AUTO_START drivers.

    For additional information about Dependencies, see Specifying Driver Load Order.

Registering for Event Logging

An AddService directive also can reference an event-log-install-section elsewhere in the INF file. Each such section has the following form:

[event-log-install-section]
 

AddReg=add-registry-section[, add-registry-section]...
[DelReg=del-registry-section[, del-registry-section]...]
[BitReg=bit-registry-section[,bit-registry-section]...]
...

For a typical device/driver INF file, the event-log-install-section uses only the AddReg directive to set up an event-logging message file for the driver. An HKR specification in an add-registry-section designates the HKLM\System\CurrentControlSet\Services\
EventLog\
EventLogType\EventName registry key. This event-logging add-registry-section has the following general form:

[drivername_EventLog_AddReg]
HKR,,EventMessageFile,0x00020000,"path\IoLogMsg.dll;path\driver.sys"
HKR,,TypesSupported,0x00010001,7

In particular, the section adds two value entries in the registry subkey created for the device/driver, as follows:

An event-log-install-section also can use the DelReg directive to remove a previously installed event-log message file, by explicitly deleting the existing EventMessageFile and TypesSupported value entries, if a driver binary is being superseded by a newly installed driver. (See also INF DelService directive.)

While a BitReg directive also is valid within an INF-writer-defined event-log-install-section, it is almost never used, because the standard value entries for device driver event logging are not bitmasks.

Example

This example shows the service-install and event-log-install sections referenced by the AddService directive as already shown earlier in the example for DDInstall.Services.

[sermouse_Service_Inst]
DisplayName    = %sermouse.SvcDesc%
ServiceType    = 1                   ; = SERVICE_KERNEL_DRIVER
StartType      = 3                   ; = SERVICE_DEMAND_START
ErrorControl   = 1                   ; = SERVICE_ERROR_NORMAL
ServiceBinary  = %12%\sermouse.sys
LoadOrderGroup = Pointer Port
 
[sermouse_EventLog_Inst]
AddReg = sermouse_EventLog_AddReg
 
[sermouse_EventLog_AddReg]
HKR,,EventMessageFile,0x00020000,"%%SystemRoot%%\System32\IoLogMsg.dll;
       %%SystemRoot%%\System32\drivers\sermouse.sys"
;
; Preceding entry on single line in INF file. Enclosing quotation marks 
; prevent the semicolon from being interpreted as a comment.
;
HKR,,TypesSupported,0x00010001,7
 
[mouclass_Service_Inst]
DisplayName    = %mouclass.SvcDesc%
ServiceType    = 1                   ; = SERVICE_KERNEL_DRIVER
StartType      = 1                   ; = SERVICE_SYSTEM_START
ErrorControl   = 1                   ; = SERVICE_ERROR_NORMAL
ServiceBinary  = %12%\mouclass.sys
LoadOrderGroup = Pointer Class
 
[mouclass_EventLog_Inst]
AddReg = mouclass_EventLog_AddReg
 
[mouclass_EventLog_AddReg]
HKR,,EventMessageFile,0x0002000,"%%SystemRoot%%\System32\IoLogMsg.dll;
       %%SystemRoot%%\System32\drivers\mouclass.sys"
HKR,,TypesSupported,0x00010001,7
; ...
[Strings]
; ...
sermouse.SvcDesc = "Serial Mouse Driver"
mouclass.SvcDesc = "Mouse Class Driver"

The example in the reference for the DDInstall.HW section, described earlier, also shows some service-install sections referenced by the AddService directive to set up PnP upper-filter drivers.

See Also

AddReg, BitReg, CopyFiles, DDInstall.HW, DDInstall.Services, DelReg, DelService, DestinationDirs, Strings