Unexepcted behavior uninstalling Primitive Driver

n4r1B 21 Reputation points
2022-04-22T19:04:43.35+00:00

I'm just testing how Primitive Drivers work by creating a FiDO that will attach to multiple stacks, since the driver is not tied to any hardware I believe this is the ideal situation to use a Primitive Driver. I'm using the following INF file:

[Version]
Signature="$WINDOWS NT$"
Class=TestPrimitiveDriver
ClassGuid={2388B6BD-B83D-4FDE-A6B7-7A06E124CA50}
Provider=%ManufacturerName%
DriverVer=
CatalogFile=TestPrimitiveDriver.cat
PnpLockdown=1

[DestinationDirs]
DefaultDestDir = 13

[SourceDisksNames]
1 = %DiskName%,,,""

[SourceDisksFiles]
TestPrimitiveDriver.sys = 1,,

[DefaultInstall.NTamd64]
CopyFiles = MyCopyFiles
AddReg = MyAddReg

[MyCopyFiles]
TestPrimitiveDriver.sys

[MyAddReg]
HKLM, System\CurrentControlSet\Control\Class\{4d36e967-e325-11ce-bfc1-08002be10318}, UpperFilters, 0x00010008, PrimitiveDriverSvc ;disk
HKLM, System\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}, UpperFilters, 0x00010008, PrimitiveDriverSvc ;cd-rom

[DefaultInstall.NTamd64.Services]
AddService = PrimitiveDriverSvc,, MyService_Install

[MyService_Install]
DisplayName    = PrimitiveDriverSvc
ServiceType    = 1               ; SERVICE_KERNEL_DRIVER
StartType      = 0               ; SERVICE_BOOT_START
ErrorControl   = 1               ; SERVICE_ERROR_NORMAL
ServiceBinary  = %13%\TestPrimitiveDriver.sys
LoadOrderGroup = "PnP Filter"

To install I don't have any problem using DiInstallDriver, the driver gets copied to the DriverStore and the RegKeys and Service are created correctly.
Unfortunately, running DiUninstallDriver is not working as expected since the RegKeys and the Service are not being removed but the driver is actually being removed from the DriverStore. Looking at the SetupAPI log is even more surreal, this is the output of the uninstall command -- Logging most verbose for General and Device:

>>>  [Driver Uninstall (DiUninstallDriver) - .\TestPrimitiveDriver\TestPrimitiveDriver.inf]

>>>  Section start 2022/04/22 11:48:02.448

      cmd: "C:\Users\n4r1B\Desktop\TestPrimitiveDriverInstaller.exe" uninstall .\TestPrimitiveDriver\TestPrimitiveDriver.inf
     ndv: Flags: 0x00000000
     ndv: INF path: C:\Users\n4r1B\Desktop\TestPrimitiveDriver\TestPrimitiveDriver.inf
     dvs: {DrvSetupUninstallDriver - C:\Users\n4r1B\Desktop\TestPrimitiveDriver\TestPrimitiveDriver.inf}
     dvs:      Flags: 0x00000000
     dvs:      {Driver Setup Delete Driver Package: oem2.inf} 11:48:02.465
     utl:           INF 'oem2.inf' is removable.
     utl:           Driver package is allowed to be unconfigured.
     ump:           Delete flags: 0x00000002
     ump:           Creating process: DrvInst.exe 11:48:02.495
     pol:           {Driver package policy check} 11:48:02.500
     pol:           {Driver package policy check - exit(0x00000000)} 11:48:02.501
     sto:           {Unstage Driver Package: C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf} 11:48:02.501
     sto:                {Core Driver Package Delete: testprimitivedriver.inf_amd64_6de13b8e0803e593} 11:48:02.502
     sto:                     {DRIVERSTORE DELETE BEGIN} 11:48:02.503
     inf:                          Opened INF: 'C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf' ([strings])
     sto:                     {DRIVERSTORE DELETE BEGIN: exit(0x00000000)} 11:48:02.504
     sto:                     {Unconfigure Driver Package: C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf}
     sto:                          Driver Package = testprimitivedriver.inf_amd64_6de13b8e0803e593
     sto:                          Flags          = 0x00000002
     inf:                          Opened INF: 'C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf' ([strings])
!    sto:                          Device class {2388b6bd-b83d-4fde-a6b7-7a06e124ca50} does not exist. Error = 0x00000002
     inf:                          Class GUID     = {2388b6bd-b83d-4fde-a6b7-7a06e124ca50}
     inf:                          Opened INF: 'C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf' ([strings])
     idb:                          Active configurations for 'oem2.inf':
     idb:                               DefaultInstall.NTamd64
     inf:                          Schema extension {2388b6bd-b83d-4fde-a6b7-7a06e124ca50} not found.
     inf:                          {Unconfigure Driver: DefaultInstall.NTamd64}
     inf:                               Manufacturer = n4r1b
     inf:                               Section Name = DefaultInstall.NTamd64
     inf:                               Driver Type  = Primitive
     sto:                               Finding all driver package versions:
     sto:                                    testprimitivedriver.inf_amd64_6de13b8e0803e593 [oem2.inf] - 04/22/2022,20.42.17.709 (Active)
!    inf:                               Driver configures class filter [UpperFilters] for {4d36e967-e325-11ce-bfc1-08002be10318} device class.
!    sto:                               Skipping driver unconfiguration to preserve existing class filters.
     inf:                               {Add Service: PrimitiveDriverSvc}
!    inf:                                    Could not reference service 'PrimitiveDriverSvc' against last owner. Error = 0x00000002
     inf:                               {Add Service: exit(0x00000000)}
     inf:                               AddReg: HKLM\System\CurrentControlSet\Control\Class\{4d36e967-e325-11ce-bfc1-08002be10318}\UpperFilters
     inf:                               Registry key 'HKLM\System\CurrentControlSet\Control\Class\{4d36e967-e325-11ce-bfc1-08002be10318}\UpperFilters' remains with owner '!testprimitivedriver.inf_amd64_6de13b8e0803e593'.
     inf:                               Registry key 'HKLM\System\CurrentControlSet\Control\Class\{4d36e967-e325-11ce-bfc1-08002be10318}\UpperFilters' still in use by 2 sources.
     inf:                               AddReg: HKLM\System\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}\UpperFilters
     inf:                               Registry key 'HKLM\System\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}\UpperFilters' remains with owner '!testprimitivedriver.inf_amd64_6de13b8e0803e593'.
     inf:                               Registry key 'HKLM\System\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}\UpperFilters' still in use by 1 source.
     cpy:                               Skipping isolated file 'TestPrimitiveDriver.sys'.
     sto:                               Installing primitive driver 'testprimitivedriver.inf_amd64_6de13b8e0803e593'.
     sto:                               {Configure Driver Package: C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf}
     sto:                                    Driver Package = testprimitivedriver.inf_amd64_6de13b8e0803e593
     sto:                                    Flags          = 0x80000000
     inf:                                    Opened INF: 'C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf' ([strings])
!    sto:                                    Device class {2388b6bd-b83d-4fde-a6b7-7a06e124ca50} does not exist. Error = 0x00000002
     inf:                                    Class GUID     = {2388b6bd-b83d-4fde-a6b7-7a06e124ca50}
     inf:                                    Opened INF: 'C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf' ([strings])
     idb:                                    Active configurations for 'oem2.inf':
     idb:                                         DefaultInstall.NTamd64
     inf:                                    {Configure Driver: DefaultInstall.NTamd64}
     inf:                                         Manufacturer = n4r1b
     inf:                                         Section Name = DefaultInstall.NTamd64
     inf:                                         Driver Type  = Primitive
     inf:                                         {Add Service: PrimitiveDriverSvc}
     inf:                                              Start Type    = 0
     inf:                                              Service Type  = 1
     inf:                                              Error Control = 1
     inf:                                              Image Path    = System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\TestPrimitiveDriver.sys
     inf:                                              Display Name  = PrimitiveDriverSvc
     inf:                                              Group         = PnP Filter
     inf:                                              Created new service 'PrimitiveDriverSvc'.
     inf:                                         {Add Service: exit(0x00000000)}
     inf:                                         AddReg: HKLM\System\CurrentControlSet\Control\Class\{4d36e967-e325-11ce-bfc1-08002be10318}\UpperFilters
     inf:                                         AddReg: HKLM\System\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}\UpperFilters
     cpy:                                         Skipping isolated file 'TestPrimitiveDriver.sys'.
     inf:                                    {Configure Driver: exit(0x00000000)}
     flq:                                    {FILE_QUEUE_COMMIT} 11:48:02.537
     flq:                                         No operations queued.
     flq:                                    {FILE_QUEUE_COMMIT - exit(0x00000000)} 11:48:02.538
     sto:                                    Configured driver package. Time = 16 ms
     sto:                               {Configure Driver Package: exit(0x00000000)}
     inf:                          {Unconfigure Driver: exit(0x00000000)}
     flq:                          {FILE_QUEUE_COMMIT} 11:48:02.540
     flq:                               No operations queued.
     flq:                          {FILE_QUEUE_COMMIT - exit(0x00000000)} 11:48:02.541
     idb:                          Cleared active configurations for 'oem2.inf'.
     sto:                          Unconfigured driver package. Time = 47 ms
     sto:                     {Unconfigure Driver Package: exit(0x00000000)}
     idb:                     {Unpublish Driver Package: C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf} 11:48:02.543
     idb:                          Opened driver package object 'testprimitivedriver.inf_amd64_6de13b8e0803e593' in DRIVERS database node.
     idb:                          Opened driver INF file object 'oem2.inf' in DRIVERS database node.
     idb:                          Clearing active driver package 'testprimitivedriver.inf_amd64_6de13b8e0803e593'.
     cpy:                          Unpublished 'oem2.inf'.
     inf:                          Opened INF: 'C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf' ([strings])
     idb:                          Deindexed 1 device ID for 'testprimitivedriver.inf_amd64_6de13b8e0803e593'.
     sto:                          Flushed driver database node 'DRIVERS'. Time = 15 ms
     sto:                          Flushed driver database node 'SYSTEM'. Time = 0 ms
     idb:                     {Unpublish Driver Package: exit(0x00000000)} 11:48:02.567
     idb:                     {Unregister Driver Package: C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593\testprimitivedriver.inf} 11:48:02.568
     idb:                          Unregistering driver package object 'testprimitivedriver.inf_amd64_6de13b8e0803e593' from DRIVERS database node.
     idb:                          Driver package 'testprimitivedriver.inf_amd64_6de13b8e0803e593' is registered to 'oem2.inf'.
     idb:                          Unregistered driver package 'testprimitivedriver.inf_amd64_6de13b8e0803e593' from 'oem2.inf'.
     idb:                          Deleted driver package object 'testprimitivedriver.inf_amd64_6de13b8e0803e593' from DRIVERS database node.
     idb:                          Deleted driver INF file object 'oem2.inf' from DRIVERS database node.
     idb:                     {Unregister Driver Package: exit(0x00000000)} 11:48:02.572
     cpy:                     {Delete Directory: C:\Windows\System32\DriverStore\FileRepository\testprimitivedriver.inf_amd64_6de13b8e0803e593} 11:48:02.572
     cpy:                     {Delete Directory: exit(0x00000000)} 11:48:02.573
     sto:                     {DRIVERSTORE DELETE END} 11:48:02.574
     sig:                          Uninstalled catalog 'oem2.cat'.
     sto:                     {DRIVERSTORE DELETE END: exit(0x00000000)} 11:48:02.580
     sto:                {Core Driver Package Delete: exit(0x00000000)} 11:48:02.580
     sto:           {Unstage Driver Package: exit(0x00000000)} 11:48:02.603
     ump:           Driver store delete process exited with code 0x00000000 11:48:02.607
     dvs:      {Driver Setup Delete Driver Package - exit (0x00000000)} 11:48:02.615
     dvs: {DrvSetupUninstallDriver - exit(00000000)}
<<<  Section end 2022/04/22 11:48:02.635
<<<  [Exit status: SUCCESS]

Looking at that not only it doesn't uninstall but it actually executed the DefaultInstall again, I double checked this by deleting the Service and RegKeys and execute DiUninstallDriver and to my surprise the Service/RegKeys were installed.

Am I doing something wrong in the INF, or is there an issue with the uninstall process of Primitive Drivers?

Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,543 questions
{count} votes

Accepted answer
  1. Zac Lockard 116 Reputation points Microsoft Employee
    2022-04-25T18:47:00.073+00:00

    Hi -

    This is a by-design behavior for compat reasons. For class filters registered in a legacy manner (i.e. using a registry key), we can't determine if your primitive driver is what created that service/filter or if it previously existed and removing it with your primitive driver will break something else. We have a new filter registration mechanism that does not have this problem though, and if you use it in this INF you will see the behavior you're looking for. The actual syntax docs aren't quite up yet, but we do have this guidance page on the new mechanism: Device Driver Filter Ordering

    One thing I want to note is that the new filter mechanism only alters the filters of the class the INF belongs to, so this INF would either be in the disk or cd-rom classes and you'd have a second INF for the other class. But what you'll want to do is remove the reference to MyAddReg, and replace it with this:

    [DefaultInstall.NTamd64.Filters]  
    AddFilter = PrimitiveDriverSvc,,Filter_Install  
      
    [Filter_Install]  
    FilterPosition = Upper  
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Zac Lockard 116 Reputation points Microsoft Employee
    2022-05-02T18:14:58.747+00:00

    Ah, sorry this is my mistake.

    For class filters, AddFilter can only be done on classes that have specifically enabled the AddFilter syntax. Devices do not need to enable this directly when they use FilterPosition to add upper or lower filters. Apologies for the confusion, I had forgotten this detail. There is a lot of legacy to how class filters are added on systems and the weird behavior you're seeing (plus the exemption from having AddFilter enabled by default) is reflective of that. I'm hoping to get AddFilter turned on for all classes in an upcoming release so that we can improve this situation going forward.

    1 person found this answer helpful.