问题
Can a batch file be made in windows that could safely eject the USB?So far on various sites there exist different utilities like devcon.
回答1:
Eject Media and Remove Drive
Freeware by Uwe Sieber - http://www.uwe-sieber.de
Remove drive is what you need for USB safe removal.
回答2:
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
回答3:
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%
来源:https://stackoverflow.com/questions/22705830/safely-remove-usb-from-batch-file