I am a really newbie programmer, and currently using <cfgmgr32.h>. I noticed several function I called keep on return CR_ACCESS_DENIED error back to me. I am unable to find the solution else where so I decided to came here.
Here is my code (sorry if it is messy):
DEVINST pDeviceInstance;
CONFIGRET configRet = 0;
configRet = CM_Locate_DevNodeW(&pDeviceInstance, DeviceInstanceIDW,
CM_LOCATE_DEVNODE_PHANTOM); // CR_SUCCESS
configRet = CM_Reenumerate_DevNode(pDeviceInstance, CM_REENUMERATE_RETRY_INSTALLATION |
CM_REENUMERATE_NORMAL); // CR_ACCESS_DENIED
configRet = CM_Setup_DevNode(pDeviceInstance, CM_SETUP_DEVNODE_READY); // CR_ACCESS_DENIED
PNP_VETO_TYPE vetoed;
WCHAR strVetoed;
configRet = CM_Query_And_Remove_SubTreeW(pDeviceInstance, &vetoed, &strVetoed,
MAX_PATH, CM_REMOVE_UI_OK); // CR_ACCESS_DENIED
if (configRet != CR_REMOVE_VETOED)
configRet = CM_Uninstall_DevNode(pDeviceInstance, 0); // CR_ACCESS_DENIED
I got my DeviceInstanceIDW from calling SetupDiGetDeviceInstanceId, which I am confident it is not having any issue.
I tried CM_Locate_DevNodeW first to get the DEVINST and proceed to my stuff. But right after that, I am stuck.
I noticed in the .h file it comment //NT ONLY, but I didn't managed to figure out what does that means.
My questions are:
a) What does the CR_ACCESS_DENIED actually about (as I cannot find any detailed documentation)
b) How should I solve this and make it work?
c) Is it a bad idea to use this <cfgmgr32.h>? I am actually trying to programmatically unplug and plug an USB COM device. The actual scenario is more complicated, but in simple word, this is what I am attempting to do.
I seeking to know how to make the code works, why it doesn't at first and how is the solution provided solve it. Appreciate any constructive comment. Thanks in advance.