0

I have Windows WDF device driver code, trying to make it work to preinstall (before the device is present). It starts by checking for the presence of valid device IDs, and for any that are found it does this:

if (UpdateDriverForPlugAndPlayDevices(0, // No Window Handle
    hwid, // Hardware ID
    inffile, // FileName
    INSTALLFLAG_FORCE,
    &RebootRequired))
        // success

But if no devices are present / plugged in, it does this:

if(SetupCopyOEMInf(inffile,
     NULL,
     SPOST_PATH,
     0,
     NULL,
     0,
     NULL,
     NULL))
        // etc.

In the first case (device present), all is good. But in the second case, according to Microsoft's "Preinstalling Driver Packages", it should to copy the INF to c:\Windows\inf\oem.inf (which it does) then once a device is present, it should install the driver based on the info in the INF, which it does not, and I have to go to the device manager, remove the unknown device, and scan for hardware changes to make it install.

In the first case (device present), our driver .sys file gets copied to the c:\windows\system32\drivers dir, whereas in the second case it never does. If I just separately copy the .sys file to c:\windows\system32\drivers, everything works. I can just do that but that seems kludgey (and risky) given that it's all supposed to be handled automatically, based on my reading of Microsoft's "Preinstalling Driver Packages" doc.

rwhenderson
  • 84
  • 1
  • 6

1 Answers1

0

When you preinstall the driver, it only registers that driver in the driver store. Then, when a device is plugged in that matches that preinstalled driver it will install it by copying the SYS file to the C:\Windows\system32\drivers directory and install the INF file as an OEMxx.inf file in the C:\Windows\inf\ directory.

If you call that command and the device is present, as you've seen, Windows will install the driver. If the device is not present it will install when the next device that matches it is plugged in.

You mentioned that you can manually go to device manager to "remove" and "rescan" to trigger the install. You could also had commands for this to do it programmatically after your SetupCOpyOEMInf call. See the devcon documentation, the source is available in the WDK. You can try this at the command line by using devcon remove XXXX where XXXX is some matching information on your device and devcon rescan to trigger a scan for new hardware.

Also, do not copy the SYS file to the drivers folder yourself - use the methods provided to install how Microsoft recommends - it will save you headaches later.

Preston
  • 2,543
  • 1
  • 17
  • 26