how to know for which instance of Driver Device EvtDriverDeviceAdd was called

regards,

I have multiple devices driven by same driver.
In some cases I want to disable some instances, while leaving other instances enabled.
Each instance of device has it’s own set of properties in registry in sub keys 0,1,2,…etc.
Problem is I do not know which instances are disabled at boot time.
And I want to skip disabled instance properties during initialization phase.
Is this possible without creating Device Object (would like to keep X part of ‘Device\VunaFdoX’ same as instance number)?
Or is it possible to get this immediately after Device Object is created (WdfDeviceCreate)?
Tried several things without success to identify the instances of enabled devices.

Only thing I know that might work is that I could read registry path to it (XXXX)
‘HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\VUNA\XXXX\Control’
check for existance of ActiveService and DisableCount values,
and compare with siblings which XXXX are already initialized.
I don’t think this is solution, and there has to be proper way to do it?

thank you,
and best regards

You pose an interesting question. And, of course, as with any such question, the answer is going to be “it depends”…

Problem is I do not know which instances are disabled at boot time. And I want to skip disabled instance properties during initialization phase.

Well… part of the answer here is that your driver won’t be loaded for disabled device instances. But I suspect you know that.

By design, you really don’t know too very much in EvtDriverDeviceAdd. You should be able to open your device key using WdfDeviceOpenRegistryKey (or IoOpenDeviceInterfaceRegistryKey)… but you need to be careful: You really can’t interpret the system defined values that are stored, because they’re implementation specific, and can change.

When you have multiple device instances that have external dependencies (like, device x is cabled-up to something and device y is cabled-up to something else and you want to know which device is which in your driver)… this can be a problem unless you store your own device-instance specific information (in your INF file, for example… or written by a configuration utility) in (say) your device key where your driver can later retrieve it. Or, you can change the Device ID and retrieve that (admittedly, this is a very big hammer – this is basically what Intel does in the PCH… different instances of identical internal devices have different Device IDs).

But if you really want to allow users to use (say) Device Manager to enable/disable arbitrary devices and then get your driver to understand which instance is being started… I suspect you’re going to have to content yourself with either storing your own device-specific information so you can differentiate the unit being activated, or rely on undocumented registry fields.

Peter

Thanks for input,

I did something similar called WdfFdoInitOpenRegistryKey to retrieve handle to key for driver instance, which returned handle to:
\REGISTRY\MACHINE\SYSTEM\ControlSet001\Enum\ROOT\<Class>\<NNNN>\Device Parameters
where <Class> is Class assigned during driver install procedure, and <NNNN> is the instance of driver where THIS instance will read/write its properties.
At the moment I’ve just picked up NNNN and read configuration for driver from service properties sub key with same NNNN as name. Know this is bad idea, but for the moment (testing multiple instances) it works.
Plan to replace service key configuration with INI configuration files, and place under WdfFdoInitOpenRegistryKey full path to INI file for that instance. This way I think I will ensure each instance is uniquely bound to single INI file, so after removal of Driver Instance in the middle won’t break the configuration link in other instances.

any thoughts?