Setup selects a driver for each device, unless the device is being used in raw mode. This section describes how Setup makes that selection.
Setup's concept of a driver is really a driver node, which includes all the support for a device, such as any services, device-specific co-installers, registry entries, and so forth. The services for a device can include a set of PnP drivers (a function driver and any upper and lower filter drivers).
Some devices require a vendor-supplied driver that is designed specifically for that device. Other devices can be driven by a vendor-supplied driver that is designed to support a family of devices. Still other devices can be driven by a system-supplied driver that supports all the devices of a given device setup class. To choose a driver for a device, Setup prefers a driver that is a specific match for the device. If it does not find such a driver, it chooses from successively more general drivers.
To locate a driver match, Setup compares the device's hardware IDs and compatible IDs, as reported by the device's parent bus driver, to the hardware IDs and compatible IDs listed in the INF files on the system. Setup creates a list of possible drivers for the device; that is, drivers whose INF Models section entries contain an ID that matches one of the device's IDs. (For more information about hardware IDs and compatible IDs, see Device Identification Strings.)
If Setup does not find a match in any of the installed INF files it starts up the Found New Hardware wizard, which prompts the user for a driver.
Setup assigns a "rank" to each possible driver. The rank indicates how well the driver matches the device. The lower the rank number, the better a match the driver is for the device. A rank of zero represents the best match.
For Microsoft® Windows® XP and later, some driver packages are considered to be "trusted" while others are "untrusted". All signed driver packages are trusted, and all unsigned driver packages are untrusted.
Note that a driver that is signed for a particular operating system version might not be considered to be signed for another operating system version.
For NT®-based systems, Setup assigns ranks to trusted drivers as follows.
| Trusted Driver Rank | Description |
|---|---|
| 0x0-0xFFF | Matched a device's hardware ID with the hardware ID in an INF Models section. A rank N match means that the device's N+1 hardware ID matched the INF hardware ID. |
| 0x1000-0x1FFF | Matched one of the device's hardware IDs with a compatible ID in an INF Models section. |
| 0x2000-0x2FFF | Matched one of the device's compatible IDs with the hardware ID in an INF Models section. |
| 0x3000-0x3FFF | Matched one of the device's compatible IDs with a compatible ID in an INF Models section. |
Driver ranks in the range 0x0-0xFFF are called "hardware ID matches" because they match hardware ID to hardware ID. These are the best matches. All other ranks are called "compatible ID matches" because the match involves at least one compatible ID. If Setup determines that a driver package for an NT-based system is untrusted, it raises the driver package's rank to a value within the appropriate untrusted rank range.
Setup assigns ranks to untrusted drivers as follows.
| Untrusted Driver Rank | Description |
|---|---|
| 0x8000-0x8FFF | Hardware IDs that match unsigned drivers through decorated INF sections. |
| 0x9000-0xBFFF | Compatible IDs that match unsigned drivers through decorated INF sections. |
| 0xC000-0xCFFF | Hardware IDs that match unsigned drivers through undecorated INF sections. Probably a Windows 9x/Me-only driver. |
| 0xD000-0xFFFE | Compatible IDs that match unsigned drivers through undecorated INF sections. Probably a Windows 9x/Me-only driver. |
| 0xFFFF | Worst-case match. This is a special value used by components such as co-installers. |
When Setup installs a device in the context of an administrative user process (a client-side installation), it starts the Found New Hardware wizard if the driver rank is only a compatible ID match or if its rank is within the untrusted ranges. The wizard asks the user whether he or she has a better driver for the device.
For example, consider a device with two hardware IDs and two compatible IDs. The syntax of the IDs is defined in the glossary. This discussion refers to the IDs using the following shorthand names:
HwID_1, HwID_2, CID_1, and CID_2
The first hardware ID in a list of hardware IDs is the most precise identification for the device. In this example, that is HwID_1.
For this example, assume there is a signed INF file with a Models section that has an entry like the following:
DeviceDesc1 = InstallSection1, INF_HWID_1, INF_CID_1
Again, the INF_XXX_N names are shorthand for the hardware IDs and compatible IDs listed in the INF Models section.
The following table lists the ranks for the possible matches that Setup can make when comparing the sample device's IDs against the IDs in the INF files.
| Device's IDs | IDs in INF Models Section | |
|---|---|---|
| INF_HwID_1 | INF_CID_1 | |
| HwID_1 | Rank 0 | Rank 1000-1FFF |
| HwID_2 | Rank 1 | Rank 1000-1FFF |
| CID_1 | Rank 2000-2FFF | Rank 3000-3FFF |
| CID_2 | Rank 2000-2FFF | Rank 3000-3FFF |
In this example, Setup starts by comparing the device's first hardware ID, HwID_1, with the IDs in the INF files on the system. If Setup matches the HwID_1 string with the first hardware ID listed in an INF Models section, it adds that driver node to its list of potential drivers and ranks that match as a "rank 0" match. If Setup matches any other INF Models entries with HwID_1, it ranks those matches and adds them to its list of potential drivers.
Next, Setup compares the device's additional hardware IDs, if any, with the IDs in the INF files. If it finds any matches, it ranks them and adds them to its list of potential drivers for this device. Then, it follows the same process for the device's compatible IDs, if any.
The following table lists the criteria Setup uses to select a driver for a device. The main criteria Setup uses are a driver's rank and its date and version, which are specified by the DriverVer directive that is contained in a driver's INF file. Driver signing is an additional criteria which is also used in Windows Me and Windows 2000 (see WHQL Digital Signatures).
| Windows Version | Main Criteria | Additional Criteria |
|---|---|---|
| Windows Me
Windows 2000 Windows XP |
Setup selects the driver with the lowest rank. For drivers with the same rank, Setup selects the driver with the most recent date. For the drivers with the same rank and same date, Setup can select any driver. The version is not used. | For some device setup classes, Windows Me might block installation of an unsigned driver if a signed driver is already installed for the device.
For Windows 2000, Setup selects the driver with the most recent date only if the driver package is signed. Otherwise, Setup does not use the DriverVer entries and uses a default date of 00/00/0000. |
| Windows XP SP1
Windows Server 2003 |
Setup selects the driver with the lowest rank. For drivers with the same rank, Setup selects the driver with the most recent date. For the drivers with the same rank and same date, Setup selects the driver with the highest version. For drivers with the same rank, same date, and same version, Setup can select any driver. | None. |
Class installers and co-installers can participate in driver selection by handling the DIF_SELECTBESTCOMPATDRV request (or the DIF_SELECTDEVICE request for a manually installed device). Setup sends this DIF codes after it builds its list of potential drivers but before it selects the best driver. When handling these DIF codes, a class installer or co-installer can set the DNF_BAD_DRIVER flag on a potential driver node if the installer is able to determine that the driver does not support the device. If DNF_BAD_DRIVER is set on a potential driver node, Setup ignores the driver when making its selection.
An installer can also participate in driver selection by changing the rank of a potential driver when the installer handles the DIF_SELECTBESTCOMPATDRV (or DIF_SELECTDEVICE) request. However, the only way an installer should modify driver rank is by setting the rank to 0xFFFF. This rank value indicates that the driver can be used for the device, but only as a last choice option. Installers must not set intermediate values for driver rank because they might interfere with proper driver selection and because the rank ranges are subject to change.
Instead of modifying the driver selection process, a class installer or co-installer can override Setup's entire selection process and directly choose the driver for a device. (See DIF_SELECTBESTCOMPATDRV and DIF_SELECTDEVICE for more information.) However, this is not recommended because Setup's selection algorithms might be enhanced in a future release. When an installer directly selects a driver, Setup's selection operations are terminated.
To illustrate driver selection, consider a sample video device that matches three driver nodes in the INF files on the system. The device's parent bus driver (pci.sys) reports the following device IDs:
In this example, Setup finds three driver nodes in the INF files that match the device's IDs. The first driver node in the Models section of an INF that matches is the following:
%Sample1% = Sample1.DDInstall, PCI\VEN_FFFF&DEV_493D&CC_0300
The device's fourth hardware ID matches the hardware ID in this INF entry, so this is a "rank 3" driver match. Setup adds this driver to its list of potential drivers for the device. This driver supports any video device of this type (a video device with any subsystem vendor ID and any hardware revision number).
The second INF entry that Setup matches for the device has the following driver node in its Models section:
%Sample2% = Sample2.DDInstall, \
PCI\VEN_FFFF&DEV_493D&SUBSYS_001C105D
The device's second hardware ID matches the hardware ID in this INF entry, so this is a "rank 1" driver match. Setup adds this driver to its list of potential drivers for the device. This driver supports devices with this specific subsystem vendor ID and with any hardware revision number.
The third INF entry that Setup matches for the device has the following driver node in its Models section:
%Sample3% = vga, PCI\CC_0300
The device's last compatible ID matches the hardware ID in this INF entry, so this driver match has a rank in the range 2000-2FFF. Setup adds this driver to its list of potential drivers for the device. This driver is a generic driver (the VGA driver) that supports any PCI video device.
For this example, if the co-installers and class installer do not modify the ranks that Setup assigned to the driver matches, Setup chooses the rank 1 driver, %Sample2%.