Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
Outbreaker

{Batch] Find file on the CD-ROMs

Recommended Posts

This would be my suggestion, (although the cdrom variable isn't guaranteed to be a CD-ROM).

bat_file.cmd

@ECHO OFF
SETLOCAL

(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

This 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 by Outbreaker

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 If

How 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 by Outbreaker

Share this post


Link to post
Share on other sites

1:\ Check to see if drive ready

2:\ Checks for file on drive

Save 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

Share this post


Link to post
Share on other sites

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 by Outbreaker

Share this post


Link to post
Share on other sites

The second VBS scripts works fine on my computer. You have to fill below in

File = ":\SOME_FOLDER\FILE.NAME"

The script only reports active drives, so if there nothing in the drive it

ignores that drive.

Share this post


Link to post
Share on other sites

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 by Outbreaker

Share this post


Link to post
Share on other sites

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 & Z2

My 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
---------------------------

Share this post


Link to post
Share on other sites

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 Disk

MESSAGE -> Exception Processing Message c00000013 Parameters 75b6bf7c 4 75b6bf7c 75b6bf7c

--------------------------------------------------------------------------------------------------------------------------------------------

Edited by Outbreaker

Share this post


Link to post
Share on other sites

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. :realmad:

jaclaz

Share this post


Link to post
Share on other sites

I tested your script also but it does not work no file start ore message.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 found
PAUSE
GOTO :EOF
:Out_of_loop
ECHO HERE are the other commands

Problem 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_loop
ECHO Echo No CDROM unit found
PAUSE
GOTO :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

I 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 by Outbreaker

Share this post


Link to post
Share on other sites

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 Then

TO ->

     If Obj.IsReady And Obj.DriveType = 2 or Obj.DriveType = 4 Then

Now 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 Disk

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

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 :SUB

This would be my suggestion, (although the cdrom variable isn't guaranteed to be a CD-ROM).

bat_file.cmd

@ECHO OFF
SETLOCAL

(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 by Outbreaker

Share this post


Link to post
Share on other sites

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 :SUB

This would be my suggestion, (although the cdrom variable isn't guaranteed to be a CD-ROM).

Oww, come on :blink: , 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 :EOF

Then the batch code goes:

@ECHO OFF

SETLOCAL

(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 :EOF

jaclaz

Edited by jaclaz

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...