Equivalent of “Scan For Hardware Changes” in device manager doesn't work after failed installation

血红的双手。 提交于 2019-12-08 11:10:52

问题


According to the docs the C++ functions CM_Locate_DevNodeA and CM_Reenumerate_DevNode of CfgMgr32.dll should be the programatical equivalant to the menu item scan for changed hardware in the device manager.

See 2nd answer to this question for managed code in C#.

But in contrary to the docs, the programmatical approach doesn't work always, when the Device manager operation works. This is my case:

  1. User already plugged in the USB device

  2. No driver found

  3. My installer adds the right INF-File into the Windows/inf directory

  4. CM_Reenumerate_DevNode doesn't cause the installation of the new driver

  5. Wheras "Scan for hardware changes" in device manager starts the installation with the new driver


回答1:


The driver gets recognized after reboot, when using SetupCopyOEMInf (C# example in accepted answer to this question) instead of copying the inf file to the C:\windows\inf directory. This method seems to be the equivalent of "Right click on inf file --> Install".

In my case the window "Windows can't verify the publisher of this driver software" came up because the manufacturer didn't register it. But this is a different story. However, this could have been another cause for my problem.




回答2:


I had a similar issue trying to write C++ code to replicate the Device Manager's Scan For Hardware command.

I tried using the code at https://support.microsoft.com/en-us/kb/259697.

However, it didn't work. I noticed CM_Reenumerate_DevNode returned CR_ACCESS_DENIED, which is #define CR_ACCESS_DENIED (0x00000033) // NT ONLY in Cfgmrg32.h.

According to CM_Reenumerate_DevNode function, callers of this function need SeLoadDriverPrivilege.

To get around setting this privilege in code, I ran the .exe as an administrator by right-clicking on .exe and selecting Run as administratror.



来源:https://stackoverflow.com/questions/14937261/equivalent-of-scan-for-hardware-changes-in-device-manager-doesnt-work-after-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!