Safely remove USB from batch file?

北慕城南 提交于 2019-12-05 15:57:49

Eject Media and Remove Drive
Freeware by Uwe Sieber - http://www.uwe-sieber.de

Remove drive is what you need for USB safe removal.

Download RemoveDrive.exe from http://www.uwe-sieber.de/drivetools_e.html

and then use the code below.

removedrive\x64\RemoveDrive.exe F: -L

Note that

  • F: is the drive you want to eject
  • -L means Loop

Please try this script to safely remove disk, maybe useful to you :)

@echo off
cls

set tempfile="%TEMP%\tmp_disk.dsk"
cd  %SystemRoot%\system32
echo.
echo   ...:: Safely Remove Disk ::...
echo.
echo   Select the disk volume number (if the disk has multiple volumes, select any of them)
echo.
echo.
echo list volume | diskpart | findstr /C:Volume /C:---
echo.
set /p volume="   Selected volume: "
echo.

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...
  pause
)

del /F %tempfile%
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!