Is there any way to eject external hard drive safely which is currently connected to the pc only using cmd? I can only use cmd right now and GUI is out the question.
1 Answer
You can use command below and consider changing the ParseName
parameter with your drive letter
Single line using the Run dialog or CMD:
powershell (New-Object -comObject Shell.Application).Namespace(17).ParseName(\"E:\").InvokeVerb(\"Eject\")
Using PowerShell
powershell (New-Object -comObject Shell.Application).Namespace(17).ParseName("E:").InvokeVerb("Eject")
it seems that, below option in some cases only remove the drive latter.
Use the diskpart utility to safely remove a disk drive. This is useful when you have no GUI, for example in Server Core or Hyper-V Server.
- On command prompt, type
diskpart
and wait for the new prompt, then typelist volume
. Take note of the number of your desired volume by watching its drive letter (be carefull!!!) - Type
select volume <number>
, where is the number of your USB storage. - Then, type
remove all dismount
. Typeexit
to leave diskpart. Enjoy! ;) - Now you can safely remove your USB storage device from the Hyper-V server.
According to the diskpart remove's help (type "help remove" inside diskpart):
-
I have tried doing this but the hard drive’s led is still flashing.. usually it stops flashing after ejecting.. Commented Apr 30, 2020 at 14:09
-
@ManavSinghChauhan , you are right, kindly check the updated answer, i hope this could help you Commented May 6, 2020 at 4:22
C:\Windows\System32\rundll32.exe shell32.dll,Control_RunDLL hotplug.dll
to bring up wizard to eject USB device. See if you can Google aboutControl_RunDLL hotplug.dll
and see if there's an api method or some parameter you can pass such as UUID, deviceID, or hardware name or something like that to always eject the needed device. If you can do it with C# or C code, you can run that in PowerShell which you can in turn run using native cmd only and windows CMD native with nothing further needed, period.