Windows explorer allows for a soft eject feature for USB drives that I would
like to recreate in my program. This is useful for USB drives where a
compact flash is inserted and removed but the USB drive remains connected to
the PC. Does anyone know what functions are involved to accomplish this? I
have seen code which accomplishes the hard eject (removing the entire USB
device) but not the soft eject which only flushes the cache.

Thanks

Re: How to progamatically do a USB "soft eject" like explorer by Eliyas

Eliyas
Wed May 30 11:02:02 CDT 2007

http://msdn2.microsoft.com/en-us/library/ms790891.aspx

-Eliyas

"RFlaugher" <RFlaugher@discussions.microsoft.com> wrote in message
news:C12A5645-4023-4FEB-AA24-3E541BA137D3@microsoft.com...
> Windows explorer allows for a soft eject feature for USB drives that I
> would
> like to recreate in my program. This is useful for USB drives where a
> compact flash is inserted and removed but the USB drive remains connected
> to
> the PC. Does anyone know what functions are involved to accomplish this?
> I
> have seen code which accomplishes the hard eject (removing the entire USB
> device) but not the soft eject which only flushes the cache.
>
> Thanks



Re: How to progamatically do a USB "soft eject" like explorer by RFlaugher

RFlaugher
Wed May 30 11:13:04 CDT 2007

I have tried this function and in my experience it ejects the device not the
media as the soft eject does. Unless, I have applied it incorrectly.

"Eliyas Yakub [MSFT]" wrote:

> http://msdn2.microsoft.com/en-us/library/ms790891.aspx
>
> -Eliyas
>
> "RFlaugher" <RFlaugher@discussions.microsoft.com> wrote in message
> news:C12A5645-4023-4FEB-AA24-3E541BA137D3@microsoft.com...
> > Windows explorer allows for a soft eject feature for USB drives that I
> > would
> > like to recreate in my program. This is useful for USB drives where a
> > compact flash is inserted and removed but the USB drive remains connected
> > to
> > the PC. Does anyone know what functions are involved to accomplish this?
> > I
> > have seen code which accomplishes the hard eject (removing the entire USB
> > device) but not the soft eject which only flushes the cache.
> >
> > Thanks
>
>
>

Re: How to progamatically do a USB "soft eject" like explorer by cristalink

cristalink
Wed May 30 16:22:02 CDT 2007

IOCTL_STORAGE_EJECT_MEDIA


"RFlaugher" <RFlaugher@discussions.microsoft.com> wrote in message
news:C4E6E14E-5862-4CFF-88B9-C14B83AD1A34@microsoft.com...
>I have tried this function and in my experience it ejects the device not
>the
> media as the soft eject does. Unless, I have applied it incorrectly.
>
> "Eliyas Yakub [MSFT]" wrote:
>
>> http://msdn2.microsoft.com/en-us/library/ms790891.aspx
>>
>> -Eliyas
>>
>> "RFlaugher" <RFlaugher@discussions.microsoft.com> wrote in message
>> news:C12A5645-4023-4FEB-AA24-3E541BA137D3@microsoft.com...
>> > Windows explorer allows for a soft eject feature for USB drives that I
>> > would
>> > like to recreate in my program. This is useful for USB drives where a
>> > compact flash is inserted and removed but the USB drive remains
>> > connected
>> > to
>> > the PC. Does anyone know what functions are involved to accomplish
>> > this?
>> > I
>> > have seen code which accomplishes the hard eject (removing the entire
>> > USB
>> > device) but not the soft eject which only flushes the cache.
>> >
>> > Thanks
>>
>>
>>



Re: How to progamatically do a USB "soft eject" like explorer by Uwe

Uwe
Thu May 31 02:04:26 CDT 2007

RFlaugher wrote:
> Windows explorer allows for a soft eject feature for USB drives that I would
> like to recreate in my program. This is useful for USB drives where a
> compact flash is inserted and removed but the USB drive remains connected to
> the PC. Does anyone know what functions are involved to accomplish this? I
> have seen code which accomplishes the hard eject (removing the entire USB
> device) but not the soft eject which only flushes the cache.

Open the volume using a string like "\\\\.\\X:", with GENERIC_READ
access.
Then flush the volume's cache:

FlushFileBuffers(hVol);

Then lock and dismount:

res = DeviceIoControl(hVol, FSCTL_LOCK_VOLUME, 0, 0, 0, 0, &dwRet, 0);
if ( res ) {
res = DeviceIoControl(hVol, FSCTL_DISMOUNT_VOLUME,
0, 0, 0, 0, &dwRet, 0);
}

Then eject:

if ( res ) {
res = DeviceIoControl(hVol, IOCTL_STORAGE_EJECT_MEDIA,
0, 0, 0, 0, &dwRet, 0);
}

Then close hVol. Do not eject when lock and diskmount
failed. IOCTL_STORAGE_EJECT_MEDIA is quite reckless!

By default this requires admin previleges under XP but it
can be changed by a policy:
http://www.uwe-sieber.de/usbstick_e.html#ejectmedia


Uwe


Re: How to progamatically do a USB "soft eject" like explorer by pavel_a

pavel_a
Thu May 31 03:57:01 CDT 2007

You may want to visit http://www.uwe-sieber.de/usbstick_e.html
- a very useful resource on USB drives
( Thanks, Uwe! )

--PA

"RFlaugher" wrote:
> I have tried this function and in my experience it ejects the device not the
> media as the soft eject does. Unless, I have applied it incorrectly.
>
> "Eliyas Yakub [MSFT]" wrote:
>
> > http://msdn2.microsoft.com/en-us/library/ms790891.aspx
> >
> > -Eliyas
> >
> > "RFlaugher" <RFlaugher@discussions.microsoft.com> wrote in message
> > news:C12A5645-4023-4FEB-AA24-3E541BA137D3@microsoft.com...
> > > Windows explorer allows for a soft eject feature for USB drives that I
> > > would
> > > like to recreate in my program. This is useful for USB drives where a
> > > compact flash is inserted and removed but the USB drive remains connected
> > > to
> > > the PC. Does anyone know what functions are involved to accomplish this?
> > > I
> > > have seen code which accomplishes the hard eject (removing the entire USB
> > > device) but not the soft eject which only flushes the cache.
> > >
> > > Thanks
> >
> >
> >