Outbreaker Posted May 20, 2010 Author Share Posted May 20, 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 />FixedThis script looks better then my noob script ^_^ but i have a question to understand this script better how it works.I played little bit around and change [C-Z] to [A-Z] i didn't get this "No Disk" error on the Floppy driver but if i change it to [A-B] i get the error that's what i don't get [A-Z] and [A-B] should have the same effect or not O_o ? Edited May 20, 2010 by Outbreaker Link to comment Share on other sites More sharing options...
allen2 Posted May 20, 2010 Share Posted May 20, 2010 No it is the normal behaviour of the script: it test if the CDROM variable was set before echoing an error.And the CDROM variable will took the last letter of the mounted volumes even if the file doesn't exist. Link to comment Share on other sites More sharing options...
Outbreaker Posted May 20, 2010 Author Share Posted May 20, 2010 (edited) Ok after testing all this script i have some questions 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 IfHow can i do it so the script will also search in the Harddisk drives and USB flash drives ?Is there also a batch script that can check like the VBScript if it can read on the driver and then searches for the file so i will get no popup errors on Card Readers and ohter drives. Edited May 20, 2010 by Outbreaker Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 21, 2010 Share Posted May 21, 2010 1:\ Check to see if drive ready2:\ Checks for file on driveSave as a VBS file Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") Dim Chk, File, Obj'-> Path To File Without Drive Letter File = ":\SOME_FOLDER\FILE.NAME" Chk = False'-> Loop Threw The Drives For Each Obj In Fso.Drives '-> Drive Is Ready And Check To See File Exists On Drive If Obj.IsReady And Fso.FileExists(Obj.DriveLetter & File) Then File = Obj.DriveLetter & File Chk = True End If Next '-> Check The Results If Chk = True Then WScript.Echo "Confirm " & File Else WScript.Echo "Can Not Find File" End If Link to comment Share on other sites More sharing options...
Outbreaker Posted May 21, 2010 Author Share Posted May 21, 2010 (edited) I tested it but i get always a drive A: error is there no workaround for this i think this also happens to other drives like Card Readers or is it olny the drive A that makes this problem ?The olny way i found that could work is this here hop someone can make a script with the option 2 and 4 or do even a better script http://www.devguru.com/technologies/vbscript/quickref/drive_drivetype.html Edited May 21, 2010 by Outbreaker Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 21, 2010 Share Posted May 21, 2010 The second VBS scripts works fine on my computer. You have to fill below inFile = ":\SOME_FOLDER\FILE.NAME"The script only reports active drives, so if there nothing in the drive it ignores that drive. Link to comment Share on other sites More sharing options...
Outbreaker Posted May 21, 2010 Author Share Posted May 21, 2010 (edited) I set the path to the file and there is also no disk in the floppy drive but if i start the VBScript i get a "No Disk" Error MsgBox Do you have a also a floppy drive artefact in your Computer ? Edited May 21, 2010 by Outbreaker Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 21, 2010 Share Posted May 21, 2010 No I dont have a floppy disk, but I tested on sdhc card. Try this script, it going to list each drive as either active or empty Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") Dim Obj, Z1, Z2 For Each Obj In Fso.Drives If Obj.IsReady Then Z1 = Z1 & vbCrLf & "Active" & vbTab & Obj Else Z2 = Z2 & vbCrLf & "Empty " & vbTab & Obj End If Next MsgBox Z1 & vbCrLf & Z2My Results, with no errors.------------------------------------------------------Active C:Active D:Active E:Active F:Active G:Active I:Active J:Empty H:Empty K:Empty L:Empty M:Empty N:---------------------------OK --------------------------- Link to comment Share on other sites More sharing options...
Outbreaker Posted May 21, 2010 Author Share Posted May 21, 2010 (edited) My Results, with a error on A: ->A: -> Empty (Floppy disk drive)C: -> Active (Intern SATA/AHCI Hard disk drive)D: -> Active (Extern USB 2.0 Hard disk drive 1)E: -> Active (Extern USB 2.0 Hard disk drive 2)F: -> Active (Extern USB 2.0 Hard disk drive 3)G: -> Active (Extern USB 2.0 Hard disk drive 4)H: -> Empty (DVD/CD-ROM disk drive)I: -> Active (Virtual DVD/CD-ROM disk drive)--------------------------------------------------------------------------------------------------------------------------------------------This is the exact error i get from A: -> TITTEL -> No DiskMESSAGE -> Exception Processing Message c00000013 Parameters 75b6bf7c 4 75b6bf7c 75b6bf7c-------------------------------------------------------------------------------------------------------------------------------------------- Edited May 21, 2010 by Outbreaker Link to comment Share on other sites More sharing options...
jaclaz Posted May 21, 2010 Share Posted May 21, 2010 Is there also a batch script that can check like the VBScript if it can read on the driver and then searches for the file so i will get no popup errors on Card Readers and ohter drives.BOTH the ones I posted do EXACTLY that. jaclaz Link to comment Share on other sites More sharing options...
Outbreaker Posted May 21, 2010 Author Share Posted May 21, 2010 I tested your script also but it does not work no file start ore message. Link to comment Share on other sites More sharing options...
Yzöwl Posted May 21, 2010 Share Posted May 21, 2010 I would suggest that you post exactly the content of your version of someone elses script before claiming that it doesn't work.What about the two versions I posted, do they not work? Link to comment Share on other sites More sharing options...
Outbreaker Posted May 21, 2010 Author Share Posted May 21, 2010 (edited) 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.jaclazI tried this 2 scripts but if i open the batch file nothing happens but i have now put the Script on to my Win7 laptop to test and there it works i don't get i why it doesn't work on my WinXP PC. Edited May 21, 2010 by Outbreaker Link to comment Share on other sites More sharing options...
Outbreaker Posted May 21, 2010 Author Share Posted May 21, 2010 (edited) I found out on how to include in the VBScript so that the Hard disk drive will be also searched ny simply replacing this line in the code:FORM -> If Obj.IsReady And Obj.DriveType = 4 ThenTO -> If Obj.IsReady And Obj.DriveType = 2 or Obj.DriveType = 4 ThenNow the VBScript will search CD/DVD-ROM disk drives and Hard disk drives 0 = Unknown / 1 = Removable / 2 = Fixed / 3 = Network / 4 = CD-ROM / 5 = RAM DiskHere 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 IfThis Batch script works also good only problem i have is that if i put this code in a batch file then everything that is under this script causes a code conflict because it get also called into the Script by the :SUBThis 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 21, 2010 by Outbreaker Link to comment Share on other sites More sharing options...
jaclaz Posted May 21, 2010 Share Posted May 21, 2010 (edited) This Batch script works also good only problem i have is that if i put this code in a batch file then everything that is under this script causes a code conflict because it get also called into the Script by the :SUBThis would be my suggestion, (although the cdrom variable isn't guaranteed to be a CD-ROM).Oww, come on , these are snippets, it is expected that you know basic BATCH syntax to make use of these, this is OK:SUB(SET CDROM=%1)IF EXIST "%CDROM%%MYBAT%" CALL "%CDROM%%MYBAT%"if it's at the End Of File, that works as a "Return" command for the SUBroutine.If the above three lines are not the last three in the file, change as::SUB(SET CDROM=%1)IF EXIST "%CDROM%%MYBAT%" CALL "%CDROM%%MYBAT%"GOTO :EOFThen the batch code goes:@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!<HERE GOES ANOTHER LINE OF THE BATCH><HERE GOES ANOTHER LINE OF THE BATCH><HERE GOES ANOTHER LINE OF THE BATCH><HERE GOES ANOTHER LINE OF THE BATCH><....><You should have got the idea by now >GOTO :EOF:SUB(SET CDROM=%1)IF EXIST "%CDROM%%MYBAT%" CALL "%CDROM%%MYBAT%"GOTO :EOFjaclaz Edited May 21, 2010 by jaclaz Link to comment Share on other sites More sharing options...
Recommended Posts