@ECHO OFF
:: BOOTDRV.BAT
:: Places the boot drive letter in environment variable BOOTDRV
::
:: Written by Rob van der Woude
:: http://www.xs4all.nl/~robw/rob/
::
:: Limitation: Uses COMSPEC to determine boot drive, so if a different
::             command processor was specified by either the SHELL
::             command or by a SET COMSPEC=... command, this batch file
::             will be fooled and display the wrong drive.
::
SET BOOTDRV=
ECHO %COMSPEC% | CHOICE /C:ABCDEFGHIJKLMNOPQRSTUVWXYZ > NUL
IF ERRORLEVEL  1 SET BOOTDRV=A
IF ERRORLEVEL  2 SET BOOTDRV=B
IF ERRORLEVEL  3 SET BOOTDRV=C
IF ERRORLEVEL  4 SET BOOTDRV=D
IF ERRORLEVEL  5 SET BOOTDRV=E
IF ERRORLEVEL  6 SET BOOTDRV=F
IF ERRORLEVEL  7 SET BOOTDRV=G
IF ERRORLEVEL  8 SET BOOTDRV=H
IF ERRORLEVEL  9 SET BOOTDRV=I
IF ERRORLEVEL 10 SET BOOTDRV=J
IF ERRORLEVEL 11 SET BOOTDRV=K
IF ERRORLEVEL 12 SET BOOTDRV=L
IF ERRORLEVEL 13 SET BOOTDRV=M
IF ERRORLEVEL 14 SET BOOTDRV=N
IF ERRORLEVEL 15 SET BOOTDRV=O
IF ERRORLEVEL 16 SET BOOTDRV=P
IF ERRORLEVEL 17 SET BOOTDRV=Q
IF ERRORLEVEL 18 SET BOOTDRV=R
IF ERRORLEVEL 19 SET BOOTDRV=S
IF ERRORLEVEL 20 SET BOOTDRV=T
IF ERRORLEVEL 21 SET BOOTDRV=U
IF ERRORLEVEL 22 SET BOOTDRV=V
IF ERRORLEVEL 23 SET BOOTDRV=W
IF ERRORLEVEL 24 SET BOOTDRV=X
IF ERRORLEVEL 25 SET BOOTDRV=Y
IF ERRORLEVEL 26 SET BOOTDRV=Z
IF     "%BOOTDRV%"=="" ECHO Error checking boot drive
IF NOT "%BOOTDRV%"=="" ECHO Boot drive is %BOOTDRV%:
Published in: Batch
Download

Related snippets