Reputation: 2630
I have a PC with a bunch of network cards of the same type and two drivers that can service them. When I let Windows 7 decide which driver to load, each of them is loaded with the manufacturer's drivers, and for 3 out of 4 cards, that is the desired behaviour. But the last card needs to load a different driver than the others.
This problem can be manually solved by going to the device manager, selecting "Update Driver" from the card's entry's context menu, choosing to list every available driver and then choosing the one that windows neglects (because the manufacturer's driver is signed, and mine isn't). To conduct this programmatically is the ultimate goal I pursue.
I already tried quite some things to solve this, but I still can't exactly solve the problem I am having.
The first idea was to disable the UPnP Service or similarly decline Windows' efforts to assign the drivers, but I can't because it is needed for the other cards, and the given circumstances dictate that the drivers will possibly have to be reassigned quite regularly.
I tried to use the DevCon tool, since it offers something that, at first glance, looks like an incredibly easy way to achieve my goal: A command line interface that is said to be as powerful as the device manager itself. From what the documentation says, it offers usable methods indeed, and I tried it thouroughly. But there seems to be a problem with identifying the card that I want to access uniquely. Using the DevCon Tool I can retrieve Device IDs of the following format:
PCI\VEN_XXXX&DEV_XXXX&SUBSYS_XXXXXXXX&REV_XX\X&XXXXXX&X&XXXX
This, sadly, does not help much. Until the second '\'-symbol, the IDs are the same for all four devices. I can use them to issue the commands that DevCon offers me (like listing compatibale hardware IDs or just finding them). But it seems that DevCon does not evaluate the part of the ID that follows the second '\', which means that I can not just disable one of the cards (I can indeed tell which of the cards is the one the driver of which I want to change, so no problem in that respect).
A very similar approach was to use the SetupDI Api of Windows. Actually, it is the exact API that the DevCon Tool uses (well, that's what they say, anyways). And while finding and identifying the device in questions is relatively easy (even for the C# person that I am, who never had to leave the managed world), I can not seem to find a way to do anything but enabling and disabling the device. I would most probably be able to construct a workaround if I had a way of removing the card (completely disassociate it with any driver), but I can't figure out how. Disabling the device is nice, but it preserves the driver association and therefore is not a help for me.
If you can help me refine my approaches or point me another route to try, please do so. Even if your answer does not solve my problem, your suggestion might hint me at approaches I have not yet tried, and I am desperate enough to try them all.
Upvotes: 2
Views: 2046
Reputation: 2630
The exact problem can be solved using a combination of the setupapi.dll
and newdev.dll
. Note that the latter is only available on Win7 and later. Using the device and driver enumeration functions from the setupapi you can get handles to devices and appropriate drivers from the driver store. The newdev api then offers an install function that takes a device and a driver object (retrieved from the setupapis before) and install the specified driver on the device.
Upvotes: 1