(view source code of cdrom3.bat as plain text)
@ECHO OFF
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * CDROM.BAT, Version 3.00 *
REM * Read the CD-ROM drive letter from Windows' registry *
REM * Written by Rob van der Woude *
REM * *
REM * Sorry, for 32-bit Windows only. *
REM * *
REM * Inspired by Tom Lavedas' batch file with the same *
REM * functionality, which was adapted by Bill James. *
REM * I added a second pass through the registry to skip *
REM * a ZIP drive, plus separate sections for NT 4 & 2000. *
REM * The CHOICE trick to strip the square brackets from *
REM * the registry entry's name came from "Outsider". *
REM * *
REM * Thanks, guys. *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * * * * * * * * * *
REM * Recursive calls *
REM * * * * * * * * * *
IF "%1"=="Environment" GOTO Environment
IF "%1"=="Loop" GOTO Loop
REM * * * * * * * * * * * * * * * * * *
REM * For Windows 95/98/NT4/2000 only *
REM * * * * * * * * * * * * * * * * * *
VER | FIND "Windows 9" >NUL
IF NOT ERRORLEVEL 1 GOTO Win9x
VER | FIND "Windows NT" >NUL
IF NOT ERRORLEVEL 1 GOTO NT
VER | FIND "Windows 2000" >NUL
IF NOT ERRORLEVEL 1 GOTO W2K
ECHO Sorry, for Windows 95/98/NT4/2000 only
GOTO End
:: For Windows NT4
:NT
:: Find all registry sub-keys of HKEY_LOCAL_MACHINE\SYSTEM\DISK
START /WAIT REGEDIT /E %TEMP%.\CDROM1.REG "HKEY_LOCAL_MACHINE\SYSTEM\DISK"
:: Find the CD-ROM drives and parse the strings using a subroutine
FOR /F "tokens=*" %%A IN ('TYPE %TEMP%.\CDROM1.REG ^| FIND /I "\\Device\\CdRom"') DO CALL :ParseNT4 %%A
:: Remove temporary files
GOTO Cleanup
:: Parse lines from REG file and store the results in environment variables
:ParseNT4
:: Store command line parameters in temporary variable LINE
SET Line=%*
:: Strip quotes
SET Line=%Line:"=%
:: Strip leading space in NT 4 only
VER | FIND "Windows NT" >NUL
IF NOT ERRORLEVEL 1 SET Line=%Line:~1%
:: Remove quotes, backslashes and "Device" and store drive
:: letters in environment variables named after CD-ROM devices
FOR /F "tokens=2,3 delims=\= " %%A IN ('ECHO.%Line%') DO SET %%A=%%B
:: Once more to display the result
FOR /F "tokens=2,3 delims=\= " %%A IN ('ECHO.%Line%') DO ECHO CD-ROM drive detected, drive letter assigned is %%B
:: Flush temporary variable
SET LINE=
GOTO:EOF
:: For Windows 2000
:W2K
SETLOCAL
SET CDROMS=
SET Temp1=%Temp%.\%~n0%Random%1.reg
SET Temp2=%Temp%.\%~n0%Random%2.reg
START /WAIT REGEDIT /E %Temp1% "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices"
TYPE %Temp1% > %Temp2%
TYPE %Temp2% | FIND "\\DosDevices\\" | FIND /V "\\DosDevices\\A:" | FIND "=hex:5c," > %Temp1%
FOR /F "tokens=3 delims=\:" %%A IN (%Temp1%) DO CALL :ParseW2K %%A
SET CDROMS
DEL %Temp1%
DEL %Temp2%
ENDLOCAL & SET CDROMS=%CDROMS%
GOTO:EOF
:ParseW2K
IF DEFINED CDROMS (SET CDROMS=%CDROMS%,%1:) ELSE (SET CDROMS=%1:)
GOTO:EOF
REM * * * * * * * * * * *
REM * For Windows 95/98 *
REM * * * * * * * * * * *
:Win9x
REM * * * * * * * * * * * * * * * * * * * * * * * *
REM * Make sure there is enough environment space *
REM * * * * * * * * * * * * * * * * * * * * * * * *
%COMSPEC% /E:2048 /C %0 Environment
SET CMDLINE=
CALL %TEMP%.\CDROM1.BAT
GOTO Cleanup
:Environment
REM * * * * * * * * * *
REM * Reset variables *
REM * * * * * * * * * *
SET CDROM=
SET KEY=
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * Find all registry sub-keys of HKEY_LOCAL_MACHINE\Enum\SCSI *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
START /WAIT REGEDIT /E %TEMP%.\CDROM1.REG "HKEY_LOCAL_MACHINE\Enum\SCSI"
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * Extract the registry sub-key that is NOT the ZIP *
REM * drive and store it in the environment variable KEY *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TYPE %TEMP%.\CDROM1.REG|FIND "["|FIND /V "_ZIP"|FIND /V "SCSI]"|FIND /V "&">%TEMP%.\CDROM1.TMP
ECHO.>>%TEMP%.\CDROM1.TMP
TYPE %TEMP%.\CDROM1.TMP|DATE|FIND "):"|FIND "[">%TEMP%.\CDROM1.BAT
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * Temporary batch files VOER.BAT and TYP.BAT are for Dutch Win9x *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ECHO SET KEY=%%6>VOER.BAT
ECHO SET KEY=%%4>TYP.BAT
ECHO SET KEY=%%3>CURRENT.BAT
CALL %TEMP%.\CDROM1.BAT
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * Strip the square brackets [] from the KEY variable *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ECHO ]|CHOICE /C:%KEY%; %0 Loop >%TEMP%.\CDROM1.BAT
SET KEY=
CALL %TEMP%.\CDROM1.BAT
GOTO End
:Second
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * Find all registry sub-keys of the registry entry found earlier *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
START /W REGEDIT /E %TEMP%.\CDROM1.REG "%KEY%"
REM * * * * * * * * * * * * * * * * * * * * * * *
REM * Check if this really is the CD-ROM entry *
REM * * * * * * * * * * * * * * * * * * * * * * *
TYPE %TEMP%.\CDROM1.REG|FIND "Class"|FIND "CDROM">NUL
IF ERRORLEVEL 1 GOTO NoCdRom
REM * * * * * * * * * * * * * * * * * * * * * * * *
REM * Read the drive letter assignment and store *
REM * store it in the environment variable CDROM *
REM * * * * * * * * * * * * * * * * * * * * * * * *
TYPE %TEMP%.\CDROM1.REG|FIND "CurrentDriveLetterAssignment">%TEMP%.\CDROM1.TMP
ECHO.>> %TEMP%.\CDROM1.TMP
TYPE %TEMP%.\CDROM1.TMP|DATE|FIND "):"|FIND "Assignment">%TEMP%.\CDROM1.BAT
REM * * * * * * * * * * * * * * * * * * * * * * * *
REM * Make sure there is enough environment space *
REM * * * * * * * * * * * * * * * * * * * * * * * *
SET KEY=
SET CMDLINE=
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * Temporary batch files VOER.BAT and TYP.BAT are for Dutch Win9x *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ECHO SET CDROM=%%7>VOER.BAT
ECHO SET CDROM=%%5>TYP.BAT
ECHO SET CDROM=%%4>CURRENT.BAT
CALL %TEMP%.\CDROM1.BAT
REM * * * * * * * * * * * * * * * * * *
REM * If variable not set, aparently *
REM * no CD-ROM drive was detected *
REM * * * * * * * * * * * * * * * * * *
IF "%CDROM%"=="" GOTO NoCdRom
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * Strip double quotes "" from the CDROM variable and create *
REM * a temporary batch file to change the master environment *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ECHO @ECHO OFF>%TEMP%.\CDROM1.BAT
FOR %%A IN (%CDROM%) DO ECHO SET CDROM=%%A:>>%TEMP%.\CDROM1.BAT
CALL %TEMP%.\CDROM1.BAT
REM * * * * * * * * * * * *
REM * Display the result *
REM * * * * * * * * * * * *
ECHO CD-ROM drive detected, drive letter assigned is %CDROM%
GOTO End
:NoCdRom
REM * * * * * * * * * * * *
REM * Display the result *
REM * * * * * * * * * * * *
ECHO No CD-ROM drive detected
GOTO End
:Loop
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * Strip the square brackets [] from the KEY variable *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SHIFT
IF "%1"=="]" GOTO Second
IF NOT "%1"=="[[" SET KEY=%KEY%%1
GOTO Loop
:Cleanup
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM * Clean up the ugly mess in the TEMP directory and the environment *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SET KEY=
SET CMDLINE=
IF EXIST CURRENT.BAT DEL CURRENT.BAT
IF EXIST TYP.BAT DEL TYP.BAT
IF EXIST VOER.BAT DEL VOER.BAT
IF EXIST %TEMP%.\CDROM1.* DEL %TEMP%.\CDROM1.*
:End
page last modified: 2024-04-16; loaded in 0.0083 seconds