Driver Registration
This document details the process of registering a driver with the Windows operating system, a crucial step for enabling Plug and Play (PnP) functionality.
Overview
Driver registration is the mechanism by which a driver informs the operating system about its presence, capabilities, and how it should be invoked to handle specific hardware devices. For PnP devices, this registration is vital for the system to load the correct driver when a device is detected.
Key Concepts in Driver Registration
1. INF Files
The primary method for driver registration is through INF (Information) files. An INF file is a text-based setup information file that contains installation instructions for a device and its drivers. It specifies:
- The hardware IDs of the devices the driver supports.
- The driver files to be copied to the system.
- Registry entries to be created or modified.
- Services to be installed and started.
- Any necessary pre- or post-installation tasks.
2. Hardware IDs
Every hardware device has one or more unique identifiers, known as Hardware IDs. These IDs are used by the PnP manager to match a detected device to the appropriate driver. A driver's INF file lists the Hardware IDs it can handle, enabling the PnP manager to select it during device discovery.
3. Device Setup Classes
Device Setup Classes group devices with similar functionality. When installing a driver, the INF file specifies the class to which the device belongs. This helps the PnP manager organize devices and ensures that drivers are installed in a structured manner. Common classes include:
GUID_DEVCLASS_NET(Network Adapters)GUID_DEVCLASS_DISPLAY(Display Adapters)GUID_DEVCLASS_USB(Universal Serial Bus controllers)
The Registration Process
The driver registration process is typically initiated when a device is plugged in or when the system boots and detects new hardware. The PnP manager performs the following steps:
- Device Detection: The PnP manager detects a new hardware device.
- Hardware ID Matching: It compares the Hardware IDs of the detected device against the Hardware IDs listed in the INF files of installed drivers.
- Driver Selection: If a match is found, the PnP manager selects the most appropriate driver.
- INF File Processing: The system uses the selected INF file to copy driver files, create registry entries, and configure the device.
- Driver Loading: The PnP manager loads the driver into the kernel.
Example INF File Snippet for Driver Registration
Here's a simplified example of how a driver might be registered in an INF file to support a hypothetical USB device:
[Version]
Signature="$WINDOWS NT$"
Provider=%Manufacturer%
Class=USBDevice
ClassGuid={36FC9E60-C465-11CF-8056-444553540000}
DriverVer=01/01/2023,1.0.0.0
[Manufacturer]
%ManufacturerName%=Standard,NTamd64.6.1
[Standard.NTamd64.6.1]
%MyDevice.DeviceDesc%=MyDevice_Install, USB\VID_1234&PID_5678
[MyDevice_Install.NT]
CopyFiles=MyDevice.Files
[MyDevice.Files]
myusb.sys
[SourceDisksNames]
1=%Disk1%,"",,
[SourceDisksFiles]
myusb.sys=1
[DestinationDirs]
DefaultDestDir=12
[Strings]
Manufacturer="Example Corp"
ManufacturerName="Example Corporation"
MyDevice.DeviceDesc="My Example USB Device"
Disk1="Example Driver Installation Disk"
Key Sections in an INF File for Registration
[Version]: Specifies the signature, provider, device class, and driver version.[Manufacturer]: Lists the manufacturers and their supported operating system architectures.[Manufacturer.: Associates specific hardware IDs with device descriptions for a given architecture.] [DeviceDescription.Install.: Defines installation details for a specific device, including file copying and registry modifications.] [Strings]: Provides localized names for manufacturers, devices, and other strings used in the INF file.
Note on Driver Signing
Modern Windows versions require drivers to be digitally signed to ensure their authenticity and integrity. The driver signing process is a critical part of the overall driver deployment and registration pipeline.
Programmatic Registration
While INF files are the standard for device installation and driver registration, drivers can also interact with the PnP manager programmatically using APIs like those provided by the Windows Driver Kit (WDK). For example, a user-mode driver might register itself as a service and then use PnP APIs to discover and manage devices.