Table of contents
Collapse the table of content
Expand the table of content

Installing a Filter Driver

Last Updated: 7/30/2016

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.

Installing a Device-Specific Filter Driver

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. 
CopyFiles=cdaudio_copyfiles, cdrom_copyfiles



HKR,,"UpperFilters",0x00010000,"cdaudio" ; REG_MULTI_SZ value 

DisplayName    = %cdaudio_ServiceDesc%
ServiceType    = 1     ; SERVICE_KERNEL_DRIVER
StartType      = 3     ; SERVICE_DEMAND_START
ErrorControl   = 1     ; SERVICE_ERROR_NORMAL
ServiceBinary  = %12%\cdaudio.sys

Installing a Class Filter Driver

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:


upperfilter_copyfiles = 12

CopyFiles = upperfilter_copyfiles
AddReg = upperfilter_addreg

upperfilt.sys,,,0x00004000  ; COPYFLG_IN_USE_RENAME

; append this service to existing REG_MULTI_SZ list, if any

AddService = upperfilt,,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:

  1. Call SetupInstallFilesFromInfSection for the [upperfilter_inst] section.

  2. Call SetupInstallServicesFromInfSection for the [upperfilter_inst.Services] section.

  3. 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.

© 2017 Microsoft