Outbreaker Posted May 18, 2010 Share Posted May 18, 2010 (edited) HI My little script to finde a file on the CD-ROMsIF EXIST "D:\OEM\RunOnce\Auto Setup.bat" set CDROM=D:IF EXIST "E:\OEM\RunOnce\Auto Setup.bat" set CDROM=E:IF EXIST "F:\OEM\RunOnce\Auto Setup.bat" set CDROM=F:IF EXIST "G:\OEM\RunOnce\Auto Setup.bat" set CDROM=G:...IF EXIST "Z:\OEM\RunOnce\Auto Setup.bat" set CDROM=Z:START "" /WAIT "%CDROM%\OEM\RunOnce\Auto Setup.bat"But how can i do if the file gets not found that it will write a ECHO message like put the CD in and press enter to try agan. Edited May 18, 2010 by Outbreaker Link to comment Share on other sites More sharing options...
allen2 Posted May 18, 2010 Share Posted May 18, 2010 You just need to to do something like this:SET CDROM=NONEIF EXIST "D:\OEM\RunOnce\Auto Setup.bat" set CDROM=D:IF EXIST "E:\OEM\RunOnce\Auto Setup.bat" set CDROM=E:IF EXIST "F:\OEM\RunOnce\Auto Setup.bat" set CDROM=F:IF EXIST "G:\OEM\RunOnce\Auto Setup.bat" set CDROM=G:...IF EXIST "Z:\OEM\RunOnce\Auto Setup.bat" set CDROM=Z:IF "%CDROM%"=="NONE" goto NOCDSTART "" /WAIT "%CDROM%\OEM\RunOnce\Auto Setup.bat"goto end:NOCDEcho No CDROM unit found:END Link to comment Share on other sites More sharing options...
Outbreaker Posted May 18, 2010 Author Share Posted May 18, 2010 THX a lot this works good Link to comment Share on other sites More sharing options...
jaclaz Posted May 18, 2010 Share Posted May 18, 2010 The "usual way" is something like:FOR %%A IN ( Z Y X W V U T S R Q P O N M L K J I H G F E D ) DO (IF EXIST "%%A:\OEM\RunOnce\Auto Setup.bat" set CDROM=%%A:&GOTO :Out_of_loop)ECHO Echo No CDROM unit foundPAUSEGOTO :EOF:Out_of_loopECHO HERE are the other commandsProblem is that in some PC's a Sd card slot or a stoopid multi-card readers provide a drive letter even if no media is present and this will cause a popup window when you try to access the device.Something like this should work, however:For /F "tokens=3,5 delims=\ " %%A IN ('REG QUERY HKLM\SYSTEM\MountedDevices /s ^|FIND "\DosDevices\" ^| FIND "4300640052006F006D"') DO IF EXIST "%%A\OEM\RunOnce\Auto Setup.bat" set CDROM=%%A:&GOTO :Out_of_loopECHO Echo No CDROM unit foundPAUSEGOTO :EOF:Out_of_loop"4300640052006F006D" is the binary for "CdRom" which should be present in any dosdevice that represent a CD or DVD drive.jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted May 18, 2010 Share Posted May 18, 2010 (edited) This would be my suggestion, (although the cdrom variable isn't guaranteed to be a CD-ROM).bat_file.cmd@ECHO OFFSETLOCAL(SET CDROM=)(SET MYBAT=OEM\RunOnce\Auto Setup.bat)FOR /F %%# IN ('MOUNTVOL^|FINDSTR [C-Z]:\\') DO CALL :SUB %%#IF NOT DEFINED CDROM ECHO=Correct CD-ROM Drive not found!GOTO :EOF:SUB(SET CDROM=%1)IF EXIST "%CDROM%%MYBAT%" CALL "%CDROM%%MYBAT%"<Edit />Fixed Edited May 18, 2010 by Yzöwl edited because I didn't check my own code... Link to comment Share on other sites More sharing options...
jaclaz Posted May 18, 2010 Share Posted May 18, 2010 @YzöwlI am not sure to get it. The CDROM variable is set to C:\ on first run, unless you add aSET CDROM=after the IF EXIST:@ECHO OFFSETLOCAL(SET CDROM=)(SET MYBAT=OEM\RunOnce\Auto Setup.bat)FOR /F %%# IN ('MOUNTVOL^|FINDSTR [C-Z]:\\') DO CALL :SUB %%#IF NOT DEFINED CDROM ECHO=Correct CD-ROM Drive not found!GOTO :EOF:SUBIF DEFINED CDROM GOTO :EOF(SET CDROM=%1)IF EXIST "%CDROM%%MYBAT%" CALL "%CDROM%%MYBAT%"(SET CDROM=)the CDROM is always defined as C:\ and the IF EXIST is never executed for any other drive but C:, if it is, then you have the same problem I was talking about the accessing of devices with letters but no actual media.jaclaz Link to comment Share on other sites More sharing options...
cluberti Posted May 18, 2010 Share Posted May 18, 2010 One question would be, where are we running this batch file? It might be worthwhile to see if using vbscript or powershell for this might be feasible depending on where this script is running, for what it's worth. Link to comment Share on other sites More sharing options...
jaclaz Posted May 18, 2010 Share Posted May 18, 2010 One question would be, where are we running this batch file? It might be worthwhile to see if using vbscript or powershell for this might be feasible depending on where this script is running, for what it's worth.With all due respect , why everytime someone is having some fun with good ol' BATCH, someone else comes around saying that VBS or POWERSHELL would be better? I was actually expecting gunsmokingman to post one of his nice .vbs's .... jaclaz Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 18, 2010 Share Posted May 18, 2010 Here is a VBS script to see if the optical drive is empty.Save as OpticalDriveChk.vbs Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") Dim Chk, Drv, Obj Chk = False'-> Loop Threw The Drives For Each Obj In Fso.Drives '-> Check To See If The Drive Ready And It A Optical Type If Obj.IsReady And Obj.DriveType = 4 Then Drv = Obj.DriveLetter Chk = True End If Next '-> Check The Results If Chk = True Then WScript.Echo "Confirm " & Drv Else WScript.Echo "Empty Optical Drive" End If Link to comment Share on other sites More sharing options...
cluberti Posted May 18, 2010 Share Posted May 18, 2010 hahahahahahaha - awesome! Link to comment Share on other sites More sharing options...
Yzöwl Posted May 18, 2010 Share Posted May 18, 2010 You think that's being clever…Nobody mentioned WMIC!@ECHO OFF&SETLOCAL ENABLEEXTENSIONS(SET CDROM=)FOR /F "USEBACKQ TOKENS=2 DELIMS==" %%# IN (`WMIC DATAFILE WHERE^ "FSNAME='CDFS' AND PATH='\\OEM\\RUNONCE\\' AND FILENAME='AUTO SETUP' AND EXTENSION='BAT'"^ GET Name /VALUE^|FIND "="`) DO SET "CDROM=%%~d#"&SET "FPATH=%%#"IF NOT DEFINED CDROM GOTO :EOFREM PUT YOUR COMMANDS BENEATH HEREECHO=%%CDROM%%=%CDROM%CALL "%FPATH%" Link to comment Share on other sites More sharing options...
cluberti Posted May 19, 2010 Share Posted May 19, 2010 Link to comment Share on other sites More sharing options...
CoffeeFiend Posted May 19, 2010 Share Posted May 19, 2010 why everytime someone is having some fun with good ol' BATCH, someone else comes around saying that VBS or POWERSHELL would be better? Not every time. I tend to say that a lot myself (because I think it's often very much the case and in many ways -- jscript is nice too), but for ridiculously simple things (e.g. starting an installer with a couple switches) it's just overkill. Link to comment Share on other sites More sharing options...
jaclaz Posted May 19, 2010 Share Posted May 19, 2010 You think that's being clever…Nobody mentioned WMIC!And nobody mentioned fsutil...! :http://www.msfn.org/board/index.php?showtopic=143446@ECHO OFFFOR /F "tokens=1,2 delims=\" %%A IN ('MOUNTVOL^|FINDSTR [C-Z]:\\') DO (FOR /F "tokens=1,* delims=-" %%B IN ('fsutil fsinfo drivetype %%A^|FIND /I "CD-ROM"') do (ECHO Checking drive %%B ...IF EXIST "%%B\OEM\RunOnce\Auto Setup.bat" CALL "%%B\OEM\RunOnce\Auto Setup.bat"&GOTO :EOF))ECHO \OEM\RunOnce\Auto Setup.bat NOT FOUNDPAUSEjaclaz Link to comment Share on other sites More sharing options...
cluberti Posted May 20, 2010 Share Posted May 20, 2010 why everytime someone is having some fun with good ol' BATCH, someone else comes around saying that VBS or POWERSHELL would be better? Not every time. I tend to say that a lot myself (because I think it's often very much the case and in many ways -- jscript is nice too), but for ridiculously simple things (e.g. starting an installer with a couple switches) it's just overkill.That depends on your view of simple. I prefer using something other than cmd simply because nothing ever stays "ridiculously simple" in my world. Give it time, it'll snowball into something that has to be migrated into a compiled app at some point, so I might as well use VBS or a Powershell cmdlet now, to try and stave off the inevitable longer. Link to comment Share on other sites More sharing options...
Recommended Posts