The aim
Perform a hardware reset of a specific USB dongle ANT, HID device, with Delphi app.
1. CM_Request_Device_Eject function attempt
I have tried to use the CM_Request_Device_Eject
function and it correctly ejects my device, but on some systems does not automatically start it again.
This is the code I've used for the device eject:
str := PChar(GetDeviceID(DeviceInfoData.DevInst));
status := CM_Locate_DevNodeA(dev, str, CM_LOCATE_DEVNODE_NORMAL);
status := CM_Request_Device_EjectA(dev, nil, '', 0, 0);
Is there a way to ensure that my device will start if it does not automatically start after eject when using this function ?
2. SetupDiRestartDevices function attempt
As an alternative I've tried to use the SetupDiRestartDevices
function and this one properly resets my device, but except that resets all the HID devices (such as mouse, keyboard, etc.), and this function requires administrator rights to work:
rslt1 := SetupDiRestartDevices(hDevInfo, DeviceInfoData);
How can I reset only my device with this function ?
Question
Is there a generic, recommended way to perform a hardware reset of a specific USB HID device ? Or is there a way to resolve any of the above problems ?
DeviceIoControl
withIOCTL_HID_DEACTIVATE_DEVICE
andIOCTL_HID_ACTIVATE_DEVICE
it depends on the vendor of the driver, but it may be worth a try – Torrens