PnP 筛选器驱动程序可以支持 设备设置类 中的特定设备或所有设备,并且可以附加在设备功能驱动程序下方(下层筛选器)或上方(上层筛选器)。 有关 PnP 驱动程序层的详细信息,请参阅 WDM 驱动程序的类型 。
安装特定于设备的筛选器驱动程序
在 Windows 10 版本 1903 及更高版本中,可以使用来自 INF DDInstall.Filters 节的 INF AddFilter 指令注册设备特定的筛选器驱动程序。 有关详细信息,请参阅 设备筛选器驱动程序排序 。
对于早期版本的 Windows,若要注册特定于设备的筛选器驱动程序,请通过设备的 INF 文件的 DDInstall.HW 节中的 AddReg 条目创建注册表项。 对于特定于设备的上层筛选器,请创建名为 UpperFilters 的条目。 对于特定于设备的较低筛选器,请创建名为 LowerFilters 的条目。 例如,以下 INF 摘录将 ExampleFilterDriver 安装为 ExampleFunctionDriver 驱动程序的上层筛选器:
[Example_install]
CopyFiles=Filter_copyfiles, Function_copyfiles
[Example_install.HW]
AddReg=Filter_addreg
[Example_install.Services]
AddService=ExampleFunctionDriver,0x00000002,Function_ServiceInstallSection
AddService=ExampleFilterDriver,,Filter_ServiceInstallSection
[Filter_addreg]
HKR,,"UpperFilters",0x00010000,"ExampleFilterDriver" ; REG_MULTI_SZ value
[Filter_ServiceInstallSection]
DisplayName = %Filter_ServiceDesc%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %13%\ExampleFilterDriver.sys
安装类筛选器驱动程序
若要为设备安装类安装类范围的上层或下层筛选器,可以提供安装必要服务的设备安装应用程序。 然后,应用程序可以将该服务注册为所需设备安装类的上层或下层筛选驱动程序。 若要复制服务二进制文件,应用程序可以使用 SetupInstallFilesFromInfSection。 若要安装服务,应用程序可以使用 SetupInstallServicesFromInfSection。 为了将服务注册为特定设备安装类的上层筛选器和/或下层筛选器,应用程序会调用 SetupInstallFromInfSection,以注册每个感兴趣的设备安装类,并使用从 SetupDiOpenClassRegKey 中检索到的注册表项句柄作为 RelativeKeyRoot 参数。 例如,请考虑以下 INF 部分:
[DestinationDirs]
upperfilter_copyfiles = 13
[upperfilter_inst]
CopyFiles = upperfilter_copyfiles
AddReg = upperfilter_addreg
[upperfilter_copyfiles]
upperfilt.sys,,,0x00004000 ; COPYFLG_IN_USE_RENAME
[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 = %13%\upperfilt.sys
设备安装应用程序将:
针对 [upperfilter_inst] 节调用 SetupInstallFilesFromInfSection。
为 [upperfilter_inst.Services] 部分调用 SetupInstallServicesFromInfSection。
为 [upperfilter_inst] 部分调用 SetupInstallFromInfSection,为每个要注册 upperfilt 服务的类键调用一次。
每个调用都会为 Flags 参数指定 SPINST_REGISTRY,以指示只需要执行注册表修改。