PDA

View Full Version : How to eject a cd?



angie
01-13-2003, 04:32 PM
Hi, all:
Anybody know how to eject the cd using VBScript?
Thanks beforehand!

Jama
01-24-2003, 08:15 AM
Yes I do

====================== Script =======================
Const CDROM = 4
For Each d in CreateObject("Scripting.FileSystemObject").Drives
If d.DriveType = CDROM Then
Eject d.DriveLetter & ":\"
End If
Next

Sub Eject(CDROM)
Dim ssfDrives
ssfDrives = 17
CreateObject("Shell.Application")_
.Namespace(ssfDrives).ParseName(CDROM).InvokeVerb("E&ject")
End Sub
===================== Script end =====================

Jama

dudeinAmerica
01-25-2003, 08:01 AM
This will work also:

'Place this in the declaration part of your code
Option Explicit

Private Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal _
pstrReturnString As String, ByVal uReturnLength As Long, ByVal _
wndCallback As Long) As Long
'End Declaration

'Put this anywhere in your code
Public Sub OpenOrShutCDDrive(DoorOpen As Boolean)

Dim lRet As Long

If DoorOpen Then
lRet = mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
Else
lRet = mciSendString("Set CDAudio door closed", 0&, 0&, 0)
End If

'lRet will = 0 upon success, so if you want to make this
'a function, return true if lret = 0, false otherwise

End Sub

angie
01-26-2003, 03:38 PM
Thank u for your help!
Can I do this to a DVD disk? Can I format and finalize a CD-R or DVD-R using VBScript?
Thanks...

jdharm
01-30-2003, 10:38 AM
<blockquote><font class="small">In reply to:</font><hr>

Yes I do

<hr></blockquote>

Cool Jama. Can't think of a good use for it, but its fun all the same.

Josh

[i]Sorry folks, I'm an idiot. Moose out front shoulda told ya. [i]