From: Juan Segura on
Hello:

Turning around connect and disconnect disk devices I look at
IOCTL_VOLUME_ONLINE and IOCTL_VOLUME_OFFLINE functions.
However I don't find any examples jet.
I test this (in c#):

SafeFileHandle h = CreateFile(“\\\\.\\Physicaldriver3”,
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_WRITE_THROUGH,
new SafeFileHandle(IntPtr.Zero, true));

if (!h.IsInvalid)
{
long bret = 0;
bool ret=DeviceIoControl(h,
IOCTL_VOLUME_OFFLINE,IntPtr.Zero,0,IntPtr.Zero,0,
out bret, IntPtr.Zero);


Where IOCTL_VOLUME_OFFLINE is 3, meanwhile IOCTL_VOLUME_ONLINE is 2.

The GetLastWin32Error returns 50, I thing “ERROR_NOT_SUPPORTED”.

The Physicaldriver3 is an USB Memory stick dervice.

I know others ways for disconnect USB, but my target is to reconnect the USB
without human intervention.

Thanks for your time!

--
Juan Segura
www.sd-a.com
juan(a)sd-a.com
From: Juan Segura on
I found another way:

instead IOCTL_VOLUME_OFFLINE and IOCTL_VOLUME_ONLINE I can use
IOCTL_STORAGE_EJECT_MEDIA and IOCTL_STORAGE_LOAD_MEDIA.

The Eject function works well, but the LOAD has no efect!!!

Need help, please!

--
Juan Segura
www.sd-a.com
juan(a)sd-a.com


"Juan Segura" wrote:

> Hello:
>
> Turning around connect and disconnect disk devices I look at
> IOCTL_VOLUME_ONLINE and IOCTL_VOLUME_OFFLINE functions.
> However I don't find any examples jet.
> I test this (in c#):
>
> SafeFileHandle h = CreateFile(“\\\\.\\Physicaldriver3”,
> GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
> IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
> FILE_FLAG_WRITE_THROUGH,
> new SafeFileHandle(IntPtr.Zero, true));
>
> if (!h.IsInvalid)
> {
> long bret = 0;
> bool ret=DeviceIoControl(h,
> IOCTL_VOLUME_OFFLINE,IntPtr.Zero,0,IntPtr.Zero,0,
> out bret, IntPtr.Zero);
> …
>
> Where IOCTL_VOLUME_OFFLINE is 3, meanwhile IOCTL_VOLUME_ONLINE is 2.
>
> The GetLastWin32Error returns 50, I thing “ERROR_NOT_SUPPORTED”.
>
> The Physicaldriver3 is an USB Memory stick dervice.
>
> I know others ways for disconnect USB, but my target is to reconnect the USB
> without human intervention.
>
> Thanks for your time!
>
> --
> Juan Segura
> www.sd-a.com
> juan(a)sd-a.com