@echo off set T=%SystemDrive%\TEMP set DPARTSCRIPT=%T%\diskpart.txt echo ####### %0 ####### > %DPARTSCRIPT% ( @echo.select disk 0 @echo.select partition 2 @echo.remove all dismount @echo.exit @echo. ) diskpart /s %DPARTSCRIPT% if %ERRORLEVEL% NEQ 0 ( echo ERROR: while removing the drive letter! del /F %DPARTSCRIPT% 1>nul 2>nul exit /b ) echo Drive letter removed. rem cleanup ... del /F %DPARTSCRIPT% 1>nul 2>nul echo ####### %0 #######