Safely remove USB from batch file?

Is it possible to create a batch file in windows that can safely remove the USB port? There are still different utilities on different sites, such as devcon.

+4
source share
3 answers

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

Removing a drive is what you need for safe USB removal.

+5
source

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

and then use the code below.

deletedrive \ x64 \ RemoveDrive.exe F: -L

note that

  • F: this is the disk you want to eject
  • -L means Loop
+2
source

Please try the script to safely remove the disk, maybe you will find it useful :)

@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%
+1
source

Source: https://habr.com/ru/post/1533857/


All Articles