Sign in to follow this  
Followers 0
jben

Get CDROM error

11 posts in this topic

Hey everyone. Sorry if this is slightly off topic but within my AutoIT script i'm trying to call a batch file that gets the CDROM and then copys I386 files. However this doesn't seem to work and I would greatly appreciate it if someone with more batch file knowledge than me to give me some assistance.

The code below is the problem section of the batch file. Basically the code below will work but if I have memory card readers connected then it will try and search these and come back with errors. If I remove E,F and G then these errors do not appear. Is there any way I could get around this issue?. Thanks

echo off
 
for %%a in (a b c d e f g h i) do (
    if exist %%a:\Known.File (
        SET CDROM=%%a:
    )
)
 
echo %CDROM%
 
pause

Share this post


Link to post
Share on other sites



Well, then i'm going a bit offtopic as well:

Can't you just find the CD in AutoIt and copy the files from AutoIt (Or call a copy command from DOS from within AutoIt)?

AutoIt is easier for me then a batch :D


My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well, then i'm going a bit offtopic as well:

Can't you just find the CD in AutoIt and copy the files from AutoIt (Or call a copy command from DOS from within AutoIt)?

AutoIt is easier for me then a batch :D

The problem with using your method is that virtual drives are also reported. I have code that will do this but it is going to be an hour or so before I get a chance to dig it out.

Edit: Faster than I thought. Here is a piece of code that will get you started.

CODE
$Drives = DriveGetDrive("CDROM")

For $I = 1 To Ubound($Drives) -1

MsgBox(0, "Test", "Drive " & StringUpper($Drives[$I]) & " is a " & _Drive_CDType($Drives[$I]))

Next

Func _Drive_CDType( $Drive, $Computer = ".")

If DriveGetType($Drive) <> "CDROM" Then Return SetError(1)

Local $oRtn = ""

$Drive = StringUpper($Drive)

$Obj_CD = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")

$Items = $Obj_CD.ExecQuery("Select * from Win32_CDROMDrive WHERE Id = '" & $Drive & Chr(39))

For $Item in $Items

$oRtn = StringMid($Item.DeviceID, StringInStr($Item.DeviceID, "_")+1)

If StringInStr($oRtn, "Virtual") Then

$oRtn = StringMid($oRtn, StringInStr($oRtn, "Virtual"))

$oRtn = StringReplace($oRtn, "_", " ", 1)

$oRtn = StringLeft($oRtn, 15)

Else

$oRtn = StringLeft($oRtn, StringInStr($oRtn, "_") -1)

EndIf

Next

If $oRtn = "" Then Return SetError(1)

Return $oRtn

EndFunc

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

The problem with using your method is that virtual drives are also reported. I have code that will do this but it is going to be an hour or so before I get a chance to dig it out.

Well, even if the virtual drives are reported that doesn't matter :D

You just have to search for a folder called 'I386' in every drive. If it is found, you call the (DOS) copy.


My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites

Well, even if the virtual drives are reported that doesn't matter :D

You just have to search for a folder called 'I386' in every drive. If it is found, you call the (DOS) copy.

Before I forget again, your sig is way too wide.

Now back to the issue;

Right you are, so I will look for my function that determines if a CD drive has media loaded and then just search the ones that are returned for the I386 folder.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Before I forget again, your sig is way too wide.

Now back to the issue;

Right you are, so I will look for my function that determines if a CD drive has media loaded and then just search the ones that are returned for the I386 folder.

Ahh, your the first who says that.

I'm on widescreen so I didn't notice. Sorry 'bout that. I'm gonna remove them :D

(Yeah I know, I could've edited them)

On topic:

A function that determined if media is inserted?

Sounds nice. I will keep an eye on this topic for that!


My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites

I finally got back to this thread

Use the example to test it but read the note first

CODE
;===============================================================================

; Function Name: _CDDrive_MediaLoaded()

; Description: Determine if there is media in a cd or dvd drive

; Syntax: _CDDrive_MediaLoaded()

; Parameter(s): $Drive - Drive to Check

; $Computer - Computer on which the drive is installed (default = localhost)

; Requirement(s):

; Return Value(s): Success - Media Loaded Status

; Failure Sets @Error to 1

; Author(s): George (GEOSoft) Gedye

; Modification(s):

; Note(s): In the example below, change G: to the actual drive to check

; Example(s): $L_Status = "Loaded"

; If NOT _CDDrive_MediaLoaded("G:") Then $L_Status = "Not Loaded"

; If @Error Then

; MsgBox(0, "Error", "Drive is not a CD drive")

; Else

; MsgBox(0, "Media Status", "Status = " & $L_Status)

; EndIf

;===============================================================================

Func _CDDrive_MediaLoaded($Drive, $Computer = ".")

$Drive = StringReplace(StringUpper($Drive), "\", "")

If StringRight($Drive, 1) <> ":" Then $Drive &= ":"

If DriveGetType($Drive &"\") <> "CDROM" Then Return SetError(1)

$Obj_CD = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")

$Items = $Obj_CD.ExecQuery("SELECT * FROM Win32_CDROMDrive WHERE Id = '" & $Drive & Chr(39), "WQL", 0x10 + 0x20)

If IsObj($Items) then

For $Item in $Items

If $Item.MediaLoaded Then Return 1

Return 0

Next

Endif

EndFunc


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks everyone. I tried Geosofts code which showed up the drives in a messagebox. however i'm rather confused how I could implement this into my program. Basically the purpose in checking the disk is so that if it exists then it will call i386\winnt32.exe and install recovery console.

as in %cdrom%\i386\winnt32.exe /cmdcons /unattend

I used this code:

$Drives = DriveGetDrive("CDROM")

For $I = 1 To Ubound($Drives) -1
MsgBox(0, "Test", "Drive " & StringUpper($Drives[$I]) & " is a " & _Drive_CDType($Drives[$I]))
Next

Func _Drive_CDType( $Drive, $Computer = ".")
If DriveGetType($Drive) <> "CDROM" Then Return SetError(1)
Local $oRtn = ""
$Drive = StringUpper($Drive)
$Obj_CD = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
$Items = $Obj_CD.ExecQuery("Select * from Win32_CDROMDrive WHERE Id = '" & $Drive & Chr(39))

For $Item in $Items
$oRtn = StringMid($Item.DeviceID, StringInStr($Item.DeviceID, "_")+1)
If StringInStr($oRtn, "Virtual") Then
$oRtn = StringMid($oRtn, StringInStr($oRtn, "Virtual"))
$oRtn = StringReplace($oRtn, "_", " ", 1)
$oRtn = StringLeft($oRtn, 15)
Else
$oRtn = StringLeft($oRtn, StringInStr($oRtn, "_") -1)
EndIf
Next
If $oRtn = "" Then Return SetError(1)
Return $oRtn
EndFunc
Edited by jben

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I wrote that function for a different purpose and as soon as I get a chance to look at it again I'm changing it to return numeric values based on Drive type and whether or not it is a burner.

Try this

$Drives = DriveGetDrive("CDROM")

For $I = 1 To Ubound($Drives) -1
   If _CDDrive_MediaLoaded($Drives[$I]) Then
      If FileExists($Drives[$I] & "\i386\winnt32.exe") Then
         Run ($Drives[$I] & "\i386\winnt32.exe /cmdcons /unattend")
         ExitLoop
      EndIf
   EndIf
Next

Func _CDDrive_MediaLoaded($Drive, $Computer = ".")
   $Drive = StringReplace(StringUpper($Drive), "\", "")
   If StringRight($Drive, 1) <> ":" Then $Drive &= ":"
   If DriveGetType($Drive &"\") <> "CDROM" Then Return SetError(1)
   $Obj_CD = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
   $Items = $Obj_CD.ExecQuery("SELECT * FROM Win32_CDROMDrive WHERE Id = '" & $Drive & Chr(39), "WQL", 0x10 + 0x20)
   If IsObj($Items) Then
      For $Item in $Items
         If $Item.MediaLoaded Then Return 1
         Return 0
      Next
   Endif
EndFunc
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

An old UDF here for finding a CD/DVD Rom. I used to use it in my unattended windows setup.

:D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0