Page 1 of 1

Detect the cd-rom drive letter in batch file..

Posted: 08 Dec 2009 15:14
by BILL Dos
Need to auto-install a bunch of sfx files from a cd-rom drive and not off the hard drive. If anyone has done this let me know. I have a code that runs off the Hard drive but errors out when trying to find the cd-rom drive.

Code: Select all

@ECHO OFF
cls && Color 4f
echo |set/p=Date and Current Time: %DATE%  & TIME/t
echo.
echo.
echo  Auto-Installing Applications from CD Drive   
:start
echo.
echo  Enter your CD-ROM/DVD drive letter (D,E,F,G,H,I,J,K) then press Enter
@echo off & setlocal
:LOOP
set /p drive=
if ‘%cdrom%’ == ‘D’ goto proceed
if ‘%drive%’ == ‘E’ goto proceed
if ‘%drive%’ == ‘F’ goto proceed
if ‘%drive%’ == ‘G’ goto proceed
if ‘%cdrom%’ == ‘H’ goto proceed
if ‘%drive%’ == ‘I’ goto proceed
if ‘%drive%’ == ‘J’ goto proceed
if ‘%drive%’ == ‘K’ goto proceed
if ‘%drive%’ == ‘d’ goto proceed
if ‘%drive%’ == ‘e’ goto proceed
if ‘%drive%’ == ‘f’ goto proceed
if ‘%drive%’ == ‘g’ goto proceed
if ‘%drive%’ == ‘h’ goto proceed
if ‘%drive%’ == ‘i’ goto proceed
if ‘%drive%’ == ‘j’ goto proceed
if ‘%drive%’ == ‘k’ goto proceed
cls
goto error
:error
echo.
echo  The drive letter you entered was not recognized
echo.
pause
cls
goto start
:proceed
cls
echo.
echo Would you like to Begin Installs from this Drive %drive%:?
echo.
echo Type Y for Yes or N for NO then press ENTER
set /p ok=
if ‘%ok%’ == ‘y’ goto yes
if ‘%ok%’ == ‘Y’ goto yes
if ‘%ok%’ == ‘n’ goto no
if ‘%ok%’ == ‘N’ goto no
cls
:yes
ECHO Installing App1...
start /wait %CDDRIVE%\Installs\app1.exe
ECHO Installing APP2...
regedit /s %CDDRIVE%\Installs\app2.exe
ECHO Installing APP3...
regedit /s %CDDRIVE%\Installs\app3.exe

END

Posted: 10 Dec 2009 12:31
by avery_larry
You can use "if exist" and a for loop to try and determine the cdrom drive letter:


Code: Select all

for /f %%a in (z y x w v u t s r q ......) do (
   if exist %%a\installs\app1.exe (
      set cddrive=%%a
      goto :continue
   )
)
:continue
if not defined cddrive echo No cd drive found.&&goto :eof
echo cd drive letter = %cddrive%


You could combine this with output from "fsutil fsinfo drives". I'm not certain how well this method handles invalid or "not ready" drive letters.

Posted: 20 Dec 2009 05:27
by BILL Dos
Thanx for the tip Larry .. Seems that all my bottleneck code needed was to include the command set tagfile=\ which in my case i used set tagfile=\win51 and had the win51 file on the root of the CD-ROM Drive with included Installs folder of files. Below is a snippet of my working batch file.

Code: Select all


@ECHO OFF
cls && Color 4F
REM Searching for CD-ROM drive letter and determine the startup path.
set tagfile=\win51
for %%i in (D E F G H I) do if exist %%i:\win51 set CDROM=%%i:
echo.
echo Found CD-ROM as Drive  %CDROM%
echo.
echo.
echo Would you like to Begin Installs from Drive %CDROM%?
echo.
echo Type Y for YES or N for NO then press ENTER:
set /p ok=
if ‘%ok%’ == ‘y’ goto yes
if ‘%ok%’ == ‘Y’ goto yes
if ‘%ok%’ == ‘n’ goto no
if ‘%ok%’ == ‘N’ goto no
cls
:yes
cls
Echo Importing Registry Tweaks...
regedit /s %cdrom%\Installs\Tweaksx86.reg

Echo Importing System32 Files over...
xcopy %cdrom%\Installs\Sys32x86\*.* "%windir%\system32" /s /q

Echo Installing App1...
start /wait %cdrom%\Installs\App1.exe

Echo Installing App2...
start /wait %cdrom%\Installs\vbrun60sp6.exe /q:a

Echo Installing App3...
start /wait %cdrom%\Installs\ActiveSync.exe"/s /v"/qb

Echo Installing App4...
msiexec.exe /I "%cdrom%\Installs\Plus\Microsoft Plus!.msi"/qb

Echo Installing Update KB835221...
%cdrom%\Q835221.exe /z /m /q

Echo Cleaning Up then restarting Windows...
start /wait %cdrom%\Installs\CleanupX86.cmd
Rem ***Restarting to finalize installs***
%cdrom%\Installs\restart.exe
EXIT