Remove USB device from command line
Besides Uwe Sieber's RemoveDrive mentioned in the other answer, there are a whole bunch of utilities that can accomplish this. A small list follows:
USB Disk Ejector is primarily a GUI-based utility but can be used equally well from the command-line to eject the drive that the program is running from, or any drive by specifying the drive letter / (partial) drive name / mountpoint etc. Free and open source.
USB Safely Remove is not free but it's a disk removal utility on steroids, with lots of advanced features, including of course command-line support. Zentimo is its bigger brother, with even more features.
Microsoft's own DevCon is the command-line version of Device Manager. Besides the original Win2K/XP-era version available from the KB page, there are newer releases (both 32 and 64-bit) available from various MS sources as mentioned in this Where to find DevCon.exe article. DevCon.exe for Windows 7 (and probably Windows 8 as well) can be found buried in the appropriate Windows Driver Kit (WDK), as mentioned in this thread (which also contains download links to the extracted executable).
devcon status *
ordevcon hwids *
ordevcon findall =usb
(for a more compact listing) should tell you the hardware ID of the device. For example:USB\VID_0781&PID_7113\0001162825
Name: USB Mass Storage Device
Driver is running.You can then try removing the device with
devcon remove "USB\VID_0781&PID_7113"
(wildcards like * are allowed, but be careful or you might end up removing something else entirely!)
Someone asked "Is there a DOS prompt (cmd.exe from Win7) command to eject a thumb drive?" which was unfortunately closed as a duplicate of this thread. However, the question was about ejecting USB drives while in the Windows Recovery Console / System Recovery Command Prompt, so it is unlikely any of the utilities above will help. In such a situation, the following method using Diskpart should work:
Type
diskpart
and wait for the diskpart prompt (DISKPART>
)Type
list volume
Note the volume number of the USB drive carefully (use listed properties such as drive letter, label, type and size for help)
Type
select volume <number>
, where<number>
is the volume number noted aboveType
remove all dismount
Type
exit
to quit Diskpart
Now you should be able to safely remove your USB drive without fear of data loss.
RemoveDrive has served me well in the past
To answer to this question... You don't need third party stuff.
With a Command Line (or PowerShell), how can I tell Windows to safely remove the hardware automatically without user input?
Run this command: RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll
to bring up the Safely Remove Hardware dialog box: