Safely remove USB from batch file?

霸气de小男生 提交于 2020-01-13 11:34:12

问题


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

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