Installing a Filter Driver
A PnP filter driver can support a specific device or all devices in a setup class and can attach below a device's function driver (a lower filter) or above a device's function driver (an upper filter). See Types of WDM Drivers for more information about PnP driver layers.
To register a device-specific filter driver, create a registry entry through an AddReg entry in the DDInstall.HW section of the device's INF file. For a device-specific upper filter, create an entry named UpperFilters. For a device-specific lower filter, create an entry named LowerFilters. For example, the following INF excerpt installs cdaudio as an upper filter on the cdrom driver:
: ; Installation section for cdaudio. Sets cdrom as the service ; and adds cdaudio as a PnP upper filter driver. ; [cdaudio_install] CopyFiles=cdaudio_copyfiles, cdrom_copyfiles [cdaudio_install.HW] AddReg=cdaudio_addreg [cdaudio_install.Services] AddService=cdrom,0x00000002,cdrom_ServiceInstallSection AddService=cdaudio,,cdaudio_ServiceInstallSection : [cdaudio_addreg] HKR,,"UpperFilters",0x00010000,"cdaudio" ; REG_MULTI_SZ value : [cdaudio_ServiceInstallSection] DisplayName = %cdaudio_ServiceDesc% ServiceType = 1 ; SERVICE_KERNEL_DRIVER StartType = 3 ; SERVICE_DEMAND_START ErrorControl = 1 ; SERVICE_ERROR_NORMAL ServiceBinary = %12%\cdaudio.sys :
To install a class-wide upper- or lower-filter for a device setup class, you can supply a device installation application that installs the necessary services. The application can then register the service as being an upper- or lower-filter for the desired device setup classes. To copy the service binaries, the application can use SetupInstallFilesFromInfSection. To install the services, the application can use SetupInstallServicesFromInfSection. To register the services as upper- and/or lower-filters for particular device setup classes, the application calls SetupInstallFromInfSection for each device setup class of interest, using the registry key handle they retrieved from SetupDiOpenClassRegKey for the RelativeKeyRoot parameter. For example, consider the following INF sections:
: [DestinationDirs] upperfilter_copyfiles = 12 [upperfilter_inst] CopyFiles = upperfilter_copyfiles AddReg = upperfilter_addreg [upperfilter_copyfiles] upperfilt.sys [upperfilter_addreg] ; append this service to existing REG_MULTI_SZ list, if any HKR,,"UpperFilters",0x00010008,"upperfilt" [upperfilter_inst.Services] AddService = upperfilt,,upperfilter_service [upperfilter_service] DisplayName = %upperfilter_ServiceDesc% ServiceType = 1 ; SERVICE_KERNEL_DRIVER StartType = 3 ; SERVICE_DEMAND_START ErrorControl = 1 ; SERVICE_ERROR_NORMAL ServiceBinary = %12%\upperfilt.sys :
The device installation application would:
Call SetupInstallFilesFromInfSection for the [upperfilter_inst] section.
Call SetupInstallServicesFromInfSection for the [upperfilter_inst.Services] section.
Call SetupInstallFromInfSection for the [upperfilter_inst] section, once for each class key it wants to register the upperfilt service for.
Each call would specify SPINST_REGISTRY for the Flags argument, to indicate that only registry modifications need to be performed.