' **************************************************
' *
' * VCDAPIEjectAllDrives.vbs
' *
' * Copyright 2002-2003 by H+H Software GmbH
' *
' * Virtual CD v5 API example file. 
' * Ejcet all virtual CDs currently inserted.
' *
' **************************************************

Option Explicit

DIM IApi			' Virtual CD v5 API Object
DIM strVCDDrives	' existing virtual drives
DIM strVCDImage		' file name of a virtual CD
DIM strDrive		' single drive letter
DIM iLen			' string length
DIM iRC				' return value
DIM i				' Counter
DIM strTitle		' Dialog title

strTitle = "Virtual CD API Example (VCDAPIEjectAllDrives.vbs)"

' Init the VCD API object
Set IApi = CreateObject("Vc5api.Api")

' Get all exisiting virtual drive letters
strVCDDrives = IApi.VCDGetVCDDriveLetters
iLen = Len(strVCDDrives)

' only if there are virtual drives they need to be ejected
If iLen > 0 then
	
	' loop throuh the virtual drive letter
	For i = 1 to iLen step 1
		' get the next drive letter and the inserted image
		strDrive = Mid(strVCDDrives, i, 1)
		strVCDImage = IApi.VcdGetMountedFileFromDrive(strDrive)
		
		' if an image is inserted eject it
		If Len(strVCDImage) > 0 Then
			iRC = IApi.VCDEject(strDrive)
			
			' message if an error has happend
			If iRC <> 0 Then
				MsgBox "VCDEject for virtual Drive " & strDrive &": Failed (EC: " & iRC &")!", vbExclamation, strTitle
			End If
		End If
	Next
	
	If iRC = 0 THen
		MsgBox "All virtual CDs ejected!", vbInformation, strTitle
	End If
End If

Set IApi = Nothing

WScript.Quit(0)
