Post by Uwe SieberPost by TPost by JJRemounting an ejected flash drive involves disabling then re-enabling the
parent device where it is connected to. This device can be either a USB
controller, or an active USB hub. However, it can only be safely done if
there are no other USB device which are connected to the same parent device,
or if the other devices are also flash drives and have also been ejected,
because disabling the parent device will unconditionally disable all USB
devices which are connected to the parent device.
I wonder for
https://www.uwe-sieber.de/drivetools_e.html
is doing it?
Which one? RemoveDrive + RestartSrDev or EjectMedia + LoadMedia?
RestartSrDev performs a SetupDiCallClassInstaller(DIF_PROPERTYCHANGE)
call on the device itself if it has problem code 21 or for its parent
otherwise. See Microsoft DEVCON's restart command.
CM_Setup_DevNode(DevInst, CM_SETUP_PROP_CHANGE);
CM_Setup_DevNode(DevInst, CM_SETUP_DEVNODE_READY);
And since V3.0 RestartSrDev can cycle the USB device's USB port to avoid
restarting the hub with other devices attached. This works under XP with
USB ports running with the Windows standard driver and again since
Windows 8 but here it needs admin privileges.
//----------------------------------------------------------------------------------------
typedef struct _USB_CYCLE_PORT_PARAMS {
ULONG ConnectionIndex;
ULONG StatusReturned;
} USB_CYCLE_PORT_PARAMS, *PUSB_CYCLE_PORT_PARAMS;
bool CycleUsbPort(HANDLE hHub, ULONG PortNumber)
{
USB_CYCLE_PORT_PARAMS CyclePortParams = { PortNumber, 0 };
DWORD dwBytes;
int res = DeviceIoControl(hHub, IOCTL_USB_HUB_CYCLE_PORT,
&CyclePortParams, sizeof(CyclePortParams),
&CyclePortParams, sizeof(CyclePortParams),
&dwBytes, NULL);
return (res!=0 && CyclePortParams.StatusReturned==0 );
}
//----------------------------------------------------------------------------------------
See USBview how to determine hub and port number.
Uwe