Discussion:
How do I eject a flash drive and then remount it?
(too old to reply)
T
2020-09-21 08:00:57 UTC
Permalink
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
2020-09-21 11:07:34 UTC
Permalink
Post by T
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
Which one exactly?
JJ
2020-09-21 11:26:43 UTC
Permalink
Post by JJ
Post by T
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
Which one exactly?
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
2020-09-21 13:21:37 UTC
Permalink
Post by JJ
Post by JJ
Post by T
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
Which one exactly?
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.
Do you have a link to the shell api?
T
2020-09-21 20:59:39 UTC
Permalink
Post by JJ
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
2020-09-22 07:07:12 UTC
Permalink
Post by T
Post by JJ
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?
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
2020-09-22 07:14:22 UTC
Permalink
Post by Uwe Sieber
Post by T
Post by JJ
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?
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
T
2020-09-22 23:48:45 UTC
Permalink
Post by Uwe Sieber
Post by Uwe Sieber
Post by T
Post by JJ
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?
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
Thank you!

Loading...