I have various WD external drives. Sometimes a drive cannot be 'disconnected' (in use-error).
Am using below script, with thanks to Diego Queiroz which is using diskpart to get the disk offline.
give it a name, like DeleteUSBDrives.bat or so, rightclick, run as admin.
It works fine with me.
[code]rem Just run the .bat script as administrator, select the volume, and press ENTER.
rem After it you should be able to use "Safe remove" as usual to detach the unit.
rem This script is based on @Rook suggestion, so it uses diskpart to make the disk offline.
rem When this is done, all handles are forcibly closed.
rem The difference in this script is that it automatically make the disk back online,
rem so it can be recognized the next time it is connected to the system.
echo === Disk removal tool ===
echo Select the disk volume number
echo (if the disk has multiple volumes, select any of them)
echo list volume | diskpart | findstr /C:Volume /C:---
set /p volume=" Selected volume: "
echo select volume %volume% >>%tempfile%
echo offline disk >>%tempfile%
echo online disk >>%tempfile%
diskpart /s %tempfile% | findstr /C:"not valid"
if "%ERRORLEVEL%"=="1" (
echo Disk has been unlocked successfully. Try to safely remove it now.
del /F %tempfile%
echo any key to exit[/code]