How do I remove a USB drive using the Win32 API? I do a lot of work on embedded systems and on one of these I have to copy my programs on a USB stick and insert it into the target hardware.
Since I mostly work on the console I don't like to use the mouse and click on the small task-bar icon hundred times a day.
I'd love to write a little program to do exactly that so I can put it into my makefiles, but I haven't found any API call that does the same thing.
Any ideas?
To avoid losing data, it's important to remove external hardware like hard drives and USB drives safely. Look for the Safely Remove Hardware icon on the taskbar. If you don't see it, select Show hidden icons . Press and hold (or right-click) the icon and select the hardware you want to remove.
Right-click or press and hold on the drive that you want to remove and, in the menu that opens, choose Eject. If everything went well, you see a notification that it is Safe To Remove Hardware. Unplug the device that you no longer want to use on your Windows 10 PC, and you are done.
The most common way to safely eject your USB drive is by way of the System Tray. In the System Tray, click the “Up Arrow” icon to expand the menu. Next, double-click the “USB” icon. In the sub-menu that appears, select the “Eject <USB>” option.
You can use the CM_Request_Device_Eject() function as well as some other possibilities. Consult the following projects and articles:
DevEject: Straightforward. http://www.withopf.com/tools/deveject/
A useful CodeProject article: http://www.codeproject.com/KB/system/RemoveDriveByLetter.aspx
It looks like Sync lets you specify -e to eject removable drives. While not a win32 API, you could probably just call sync -e [drive_letter]
from your makefile.
Here is a technet article about removable storage media. Look for DismountNtmsMedia
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With