Jump to content

CDrom no disc error


myk3
 Share

Recommended Posts

My script requires the use of swapping out cds in the middle of the script. Everything works fine if i use a msgbox but i dont want the user to have to interact with the script if possible.

My current script is this. This is a WinPE enviroment.

_EjectDisc()
_Toast_Show(48,"Disc 2...","Please insert Disc 2")
do
  do
   $DriveStatus = DriveStatus("Z:\")
  until $DriveStatus = "READY"
  if not FileExists ("Z:\test.txt") then  _EjectDisc()
until FileExists("Z:\test.txt")

Func _EjectDisc()
    Local $sDrive, $aDrives, $oShell, $iTimer
    $aDrives = DriveGetDrive("all")
    If Not @error Then
        For $i = 1 To $aDrives[0]
            If DriveGetType($aDrives[$i] & "\") = "CDROM" Then
                $sDrive = StringUpper($aDrives[$i]) & "\"
                ExitLoop
            EndIf
        Next
    EndIf

    $oShell = ObjCreate("Shell.Application")
    $oShell.Namespace(17).ParseName($sDrive).InvokeVerb("Eject")

    $iTimer = TimerInit()
    While DriveStatus($sDrive) <> "NOTREADY" And TimerDiff($iTimer) < 10000
        Sleep(10)
    WEnd
EndFunc  ;==>_EjectDisc

Everything works well until the user puts in the wrong disc. When this happens it checks for the file and then if it is not the then it ejects the disc. The problem is i get the windows "No Disc" error similar to the one below.

Posted Image

Is there some kind of blocking function that does not require the user to do anything similar to a msgbox? Again if the user puts the correct disc in I do not get the error only if they put in the wrong disc.

Link to comment
Share on other sites

Replace

do
  do
   $DriveStatus = DriveStatus("Z:")
  until $DriveStatus = "READY"
  if not FileExists ("Z:test.txt") then  _EjectDisc()
until FileExists("Z:test.txt")

to

#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

...

$Mode = _WinAPI_SetErrorMode($SEM_FAILCRITICALERRORS)
While 1
    If Not FileExists('Z:test.txt') Then
        Switch _WinAPI_GetLastError()
            Case 21 ; ERROR_NOT_READY
                ; Nothing
            Case Else
                _WinAPI_EjectMedia('Z:')
        EndSwitch
    Else
        ExitLoop
    EndIf
    Sleep(100)
WEnd
_WinAPI_SetErrorMode($Mode)
Edited by Yashied
Link to comment
Share on other sites

Replace

do
  do
   $DriveStatus = DriveStatus("Z:")
  until $DriveStatus = "READY"
  if not FileExists ("Z:test.txt") then  _EjectDisc()
until FileExists("Z:test.txt")

to

#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

...

$Mode = _WinAPI_SetErrorMode($SEM_FAILCRITICALERRORS)
While 1
    If Not FileExists('Z:test.txt') Then
        Switch _WinAPI_GetLastError()
            Case 21 ; ERROR_NOT_READY
                ; Nothing
            Case Else
                _WinAPI_EjectMedia('Z:')
        EndSwitch
    Else
        ExitLoop
    EndIf
    Sleep(100)
WEnd
_WinAPI_SetErrorMode($Mode)

worked great, thanks for the help
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...