Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I eject a flash drive and then remount it?

60 views
Skip to first unread message

T

unread,
Sep 21, 2020, 4:01:02 AM9/21/20
to
Hi All,

I know this can be done because of

https://www.uwe-sieber.de/drivetools_e.html

But how do I do it myself?

Many thanks,
-T

JJ

unread,
Sep 21, 2020, 7:07:40 AM9/21/20
to
Which one exactly?

JJ

unread,
Sep 21, 2020, 7:26:48 AM9/21/20
to
For ejecting a flash drive, you can use Shell API to get the drive object of
the flash drive then invoke its "Eject" menu.

Remounting 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.

T

unread,
Sep 21, 2020, 9:21:41 AM9/21/20
to
Do you have a link to the shell api?

T

unread,
Sep 21, 2020, 4:59:43 PM9/21/20
to
On 2020-09-21 04:26, JJ wrote:
> Remounting 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?

Uwe Sieber

unread,
Sep 22, 2020, 10:38:08 AM9/22/20
to
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.
The quick and dirty way:
CM_Setup_DevNode(DevInst, CM_SETUP_PROP_CHANGE);
CM_Setup_DevNode(DevInst, CM_SETUP_DEVNODE_READY);

LoadMedia performs a IOCTL_STORAGE_LOAD_MEDIA on the disk device.


Uwe

Uwe Sieber

unread,
Sep 22, 2020, 10:46:54 AM9/22/20
to
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


T

unread,
Sep 22, 2020, 7:48:49 PM9/22/20
to
Thank you!

0 new messages