On Linux I can unmount a device with umount or eject. On Mac you can use diskutil. Is there a way to unmount devices so that they can be safely removed on Windows?
1 Answer
Well, according to this article:
... the answer is that there isn't one. No Microsoft-only command can eject a usb drive just like "Safely Remove Hardware" does it.
It even links to this other article that discusses the use of a Microsoft command line tool named devcon
There are some warnings: devcon doesn't just remove/eject the media in the drive, it removes/ejects the drive itself -- you might need to reinstall the hardware, unplug and restart the device, or restart the computer and hope that new hardware is detected. This is not great.
As of November 2021, the PnPUtil tool should be used instead of devcon, but even this seems to be for mass operations with device drivers, and not the media in the drive.
The closest I could come was
RunDll32.exe shell32.dll,Control_RunDLL hotplug.dlland even this only opens the "Safely Remove Hardware" dialogue box. You still need to use your mouse to select the media from a list, and click "Stop".