Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for cdrom.bat

(view source code of cdrom.bat as plain text)

  1. @ECHO OFF
  2. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3. REM * CDROM.BAT,  Version 1.00                            *
  4. REM * Read the CD-ROM drive letter from Win9x's registry  *
  5. REM * Written by Rob van der Woude                        *
  6. REM *                                                     *
  7. REM * Sorry, for Windows 95 and 98 only.                  *
  8. REM *                                                     *
  9. REM * Inspired by Tom Lavedas' batch file with the same   *
  10. REM * functionality, which was adapted by Bill James, I   * 
  11. REM * added a second pass through the registry to skip    *
  12. REM * a ZIP drive.                                        *
  13. REM * The CHOICE trick to strip the square brackets from  *
  14. REM * the registry entry's name came from "Outsider".     *
  15. REM *                                                     *
  16. REM * Thanks, guys.                                       *
  17. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  18.  
  19. REM * * * * * * * * * *
  20. REM * Recursive calls *
  21. REM * * * * * * * * * *
  22. IF "%1"=="Environment" GOTO Environment
  23. IF "%1"=="Loop"        GOTO Loop
  24.  
  25. REM * * * * * * * * * * * * * * * * * * * * * * * *
  26. REM * Make sure there is enough environment space *
  27. REM * * * * * * * * * * * * * * * * * * * * * * * *
  28. %COMSPEC% /E:2048 /C %0 Environment
  29. SET CMDLINE=
  30. CALL %TEMP%.\CDROM1.BAT
  31. GOTO Cleanup
  32.  
  33. :Environment
  34. REM * * * * * * * * * *
  35. REM * Reset variables *
  36. REM * * * * * * * * * *
  37. SET CDROM=
  38. SET KEY=
  39.  
  40. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  41. REM * Find all registry sub-keys of HKEY_LOCAL_MACHINE\Enum\SCSI  *
  42. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  43. START /W REGEDIT /E %TEMP%.\CDROM1.REG "HKEY_LOCAL_MACHINE\Enum\SCSI"
  44.  
  45. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  46. REM * Extract the registry sub-key that is NOT the ZIP    *
  47. REM * drive and store it in the environment variable KEY  *
  48. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  49. TYPE %TEMP%.\CDROM1.REG|FIND "["|FIND /V "_ZIP"|FIND /V "SCSI]"|FIND /V "&">%TEMP%.\CDROM1.TMP
  50. ECHO.>>%TEMP%.\CDROM1.TMP
  51. TYPE %TEMP%.\CDROM1.TMP|DATE|FIND "):"|FIND "[">%TEMP%.\CDROM1.BAT
  52.  
  53. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  54. REM * Temporary batch files VOER.BAT and TYP.BAT are for Dutch Win9x  *
  55. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  56. ECHO SET KEY=%%6>VOER.BAT
  57. ECHO SET KEY=%%4>TYP.BAT
  58. ECHO SET KEY=%%3>CURRENT.BAT
  59. CALL %TEMP%.\CDROM1.BAT
  60.  
  61. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  62. REM * Strip the square brackets [] from the KEY variable  *
  63. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  64. ECHO ]|CHOICE /C:%KEY%; %0 Loop >%TEMP%.\CDROM1.BAT
  65. SET KEY=
  66. CALL %TEMP%.\CDROM1.BAT
  67. GOTO End
  68.  
  69. :Second
  70. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  71. REM * Find all registry sub-keys of the registry entry found earlier  *
  72. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  73. START /W REGEDIT /E %TEMP%.\CDROM1.REG "%KEY%"
  74.  
  75. REM * * * * * * * * * * * * * * * * * * * * * * *
  76. REM * Check if this really is the CD-ROM entry  *
  77. REM * * * * * * * * * * * * * * * * * * * * * * *
  78. TYPE %TEMP%.\CDROM1.REG|FIND "Class"|FIND "CDROM">NUL
  79. IF ERRORLEVEL 1 GOTO NoCdRom
  80.  
  81. REM * * * * * * * * * * * * * * * * * * * * * * * *
  82. REM * Read the drive letter assignment and store  *
  83. REM * store it in the environment variable CDROM  *
  84. REM * * * * * * * * * * * * * * * * * * * * * * * *
  85. TYPE %TEMP%.\CDROM1.REG|FIND "CurrentDriveLetterAssignment">%TEMP%.\CDROM1.TMP
  86. ECHO.>> %TEMP%.\CDROM1.TMP
  87. TYPE %TEMP%.\CDROM1.TMP|DATE|FIND "):"|FIND "Assignment">%TEMP%.\CDROM1.BAT
  88.  
  89. REM * * * * * * * * * * * * * * * * * * * * * * * *
  90. REM * Make sure there is enough environment space *
  91. REM * * * * * * * * * * * * * * * * * * * * * * * *
  92. SET KEY=
  93. SET CMDLINE=
  94.  
  95. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  96. REM * Temporary batch files VOER.BAT and TYP.BAT are for Dutch Win9x  *
  97. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  98. ECHO SET CDROM=%%7>VOER.BAT
  99. ECHO SET CDROM=%%5>TYP.BAT
  100. ECHO SET CDROM=%%4>CURRENT.BAT
  101. CALL %TEMP%.\CDROM1.BAT
  102.  
  103. REM * * * * * * * * * * * * * * * * * *
  104. REM * If variable not set, aparently  *
  105. REM * no CD-ROM drive was detected    *
  106. REM * * * * * * * * * * * * * * * * * *
  107. IF "%CDROM%"=="" GOTO NoCdRom
  108.  
  109. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  110. REM * Strip double quotes "" from the CDROM variable and create *
  111. REM * a temporary batch file to change the master environment   *
  112. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  113. ECHO @ECHO OFF>%TEMP%.\CDROM1.BAT
  114. FOR %%A IN (%CDROM%) DO ECHO SET CDROM=%%A:>>%TEMP%.\CDROM1.BAT
  115. CALL %TEMP%.\CDROM1.BAT
  116.  
  117. REM * * * * * * * * * * * *
  118. REM * Display the result  *
  119. REM * * * * * * * * * * * *
  120. ECHO CD-ROM drive detected, drive letter assigned is %CDROM%
  121. GOTO End
  122.  
  123. :NoCdRom
  124. REM * * * * * * * * * * * *
  125. REM * Display the result  *
  126. REM * * * * * * * * * * * *
  127. ECHO No CD-ROM drive detected
  128. GOTO End
  129.  
  130. :Loop
  131. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  132. REM * Strip the square brackets [] from the KEY variable  *
  133. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  134. SHIFT
  135. IF "%1"=="]" GOTO Second
  136. IF NOT "%1"=="[[" SET KEY=%KEY%%1
  137. GOTO Loop
  138.  
  139. :Cleanup
  140. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  141. REM * Clean up the ugly mess in the TEMP directory and the environment  *
  142. REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  143. SET KEY=
  144. SET CMDLINE=
  145. IF EXIST CURRENT.BAT      DEL CURRENT.BAT
  146. IF EXIST TYP.BAT          DEL TYP.BAT
  147. IF EXIST VOER.BAT         DEL VOER.BAT
  148. IF EXIST %TEMP%.\CDROM1.* DEL %TEMP%.\CDROM1.*
  149.  
  150. :End
  151.  

page last modified: 2024-04-16; loaded in 0.0067 seconds