Click to See Complete Forum and Search --> : How To Stop a USB Storage Device


SomeCodeGuy
December 22nd, 2004, 08:55 AM
I need to add a feature to a current project to download a file to a usb music player and then stop the device - the same thing that the 'Safely Remove Hardware' program in the system tray does).

I cannot find any documentation anywhere on how to stop the device. Can you help?

Tx in advance.

NoHero
December 22nd, 2004, 09:23 AM
At first I have to say that I have never done this before. But actually I think you should do following steps:

+ Open the device by using 'CreateFile()'
+ Lock the device. If any other application is accessing the usb device the function will fail.
+ Use 'DeviceIoControl()' with following control code: IOCTL_STORAGE_EJECT_MEDIA (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/ioctl_storage_eject_media.asp)
+ Unlock the device
+ Close the handle opened by CreateFile()

If I had an USB stick or something like that, I would try it for you. But can you give it a try?