Getting the driver binary to know which device it is installed for.

Hello,

I am a beginner Windows driver developer, so I apologize if this is a no-brainer question.

I am trying to modify an existing driver to work with multiple INFs; the reason for this is that I want to install it in some cases as a real device, and in some cases as a virtual device. One INF package would correspond to the real device, and one for the virtual version. These have different device IDs and even different enumerators.

Is there a way to have the driver know which case it is being installed for? What is the most straightforward way of doing this? The driver is a WDM driver.

My initial thoughts were to check the registry; I thought I could check for the existance of a key created by Windows in the case that the device is virtual, but this does not seem to work. I’ve tried the following functions:

ZwOpenKey - This simply does not work. I get a error indicating that the key does not exist, even though I am certain that I am directing the function to the correct key. I believe that the key has not even been created yet by the time I need to call the function.
RtlCheckRegistryKey - this function gives me linker erros when I try to compile, and I think that it is not available to WDM drivers based on what I’ve read.
IoOpenDeviceRegistryKey - This function fails with a STATUS_INVALID_DEVICE_REQUEST error, and I am not certain why?

Ia this even a sensible approach to take to this kind of problem? Does anyone have any advice on why these functions could be failing, or what a sensible approach might be?

Thanks!

One inf can install for different, entirely different, enumerators.
More than one inf for a driver is complicated.

Your driver can examine its enumerator to figure out which device it
is being invoked for at its AddDevice callback routine.

For KMDF WdfFdoInitQueryProperty DevicePropertyEnumeratorName, for WDM
you can do the translation to the equivalent WDM interface.

Mark Roddy

On Sun, Sep 11, 2011 at 2:59 AM, Matthew Langille
wrote:
> Hello,
>
>
>
> I am a beginner Windows driver developer, so I apologize if this is a
> no-brainer question.
>
>
>
> I am trying to modify an existing driver to work with multiple INFs; the
> reason for this is that I want to install it in some cases as a real device,
> and in some cases as a virtual device. One INF package would correspond to
> the real device, and one for the virtual version. These have different
> device IDs and even different enumerators.
>
>
>
> Is there a way to have the driver know which case it is being installed for?
> What is the most straightforward way of doing this? The driver is a WDM
> driver.
>
>
>
> My initial thoughts were to check the registry; I thought I could check for
> the existance of a key created by Windows in the case that the device is
> virtual, but this does not seem to work. I’ve tried the following functions:
>
>
>
> ZwOpenKey - This simply does not work. I get a error indicating that the key
> does not exist, even though I am certain that I am directing the function to
> the correct key. I believe that the key has not even been created yet by the
> time I need to call the function.
>
> RtlCheckRegistryKey - this function gives me linker erros when I try to
> compile, and I think that it is not available to WDM drivers based on what
> I’ve read.
>
> IoOpenDeviceRegistryKey - This function fails with a
> STATUS_INVALID_DEVICE_REQUEST error, and I am not certain why?
>
>
>
> Ia this even a sensible approach to take to this kind of problem? Does
> anyone have any advice on why these functions could be failing, or what a
> sensible approach might be?
>
>
>
> Thanks!
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

On 11-Sep-2011 20:27, Mark Roddy wrote:

One inf can install for different, entirely different, enumerators.
More than one inf for a driver is complicated.

Your driver can examine its enumerator to figure out which device it
is being invoked for at its AddDevice callback routine.

For KMDF WdfFdoInitQueryProperty DevicePropertyEnumeratorName, for WDM
you can do the translation to the equivalent WDM interface.

Mark Roddy

That is IoGetDeviceProperty() with DevicePropertyEnumeratorName,
or perhaps DevicePropertyBusTypeGuid, or DevicePropertyHardwareID

–pa

On Sun, Sep 11, 2011 at 2:59 AM, Matthew Langille
wrote:
>> Hello,
>>
>> I am a beginner Windows driver developer, so I apologize if this is a
>> no-brainer question.
>>
>>
>>
>> I am trying to modify an existing driver to work with multiple INFs; the
>> reason for this is that I want to install it in some cases as a real device,
>> and in some cases as a virtual device. One INF package would correspond to
>> the real device, and one for the virtual version. These have different
>> device IDs and even different enumerators.
>>
>>
>>
>> Is there a way to have the driver know which case it is being installed for?
>> What is the most straightforward way of doing this? The driver is a WDM
>> driver.
>>
>>
>>
>> My initial thoughts were to check the registry; I thought I could check for
>> the existance of a key created by Windows in the case that the device is
>> virtual, but this does not seem to work. I’ve tried the following functions:
>>
>>
>>
>> ZwOpenKey - This simply does not work. I get a error indicating that the key
>> does not exist, even though I am certain that I am directing the function to
>> the correct key. I believe that the key has not even been created yet by the
>> time I need to call the function.
>>
>> RtlCheckRegistryKey - this function gives me linker erros when I try to
>> compile, and I think that it is not available to WDM drivers based on what
>> I’ve read.
>>
>> IoOpenDeviceRegistryKey - This function fails with a
>> STATUS_INVALID_DEVICE_REQUEST error, and I am not certain why?
>>
>>
>>
>> Ia this even a sensible approach to take to this kind of problem? Does
>> anyone have any advice on why these functions could be failing, or what a
>> sensible approach might be?
>>
>>
>>
>> Thanks!

Matthew Langille wrote:

I am trying to modify an existing driver to work with multiple INFs;
the reason for this is that I want to install it in some cases as a
real device, and in some cases as a virtual device. One INF package
would correspond to the real device, and one for the virtual version.
These have different device IDs and even different enumerators.

Is there a way to have the driver know which case it is being
installed for? What is the most straightforward way of doing this? The
driver is a WDM driver.

My initial thoughts were to check the registry; I thought I could
check for the existance of a key created by Windows in the case that
the device is virtual, but this does not seem to work. I’ve tried the
following functions:

IoOpenDeviceRegistryKey - This function fails with a
STATUS_INVALID_DEVICE_REQUEST error, and I am not certain why?

That is the right answer. Perhaps you should show us your code.
PLUGPLAY_REGKEY_DEVICE should open the CurrentControlSet\Enum key for
your device. That key contains a value called HardwareID that holds
your PnP ID. That should be more than enough to tell you why you were
loaded. The first part of the string is the enumerator that loaded you.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

How about simply setting a registry value in the driver key, for virtual device IDs?