Eject CD 
Author Message
 Eject CD

Hi all,

Is there any way to eject the CD using VBScript?

Thanks in advance.
Leigh




Thu, 10 Feb 2005 00:13:14 GMT  
 Eject CD

Quote:

> Hi all,

> Is there any way to eject the CD using VbScript?

Google Search: eject cd group:*.scripting
http://groups.google.com/groups?q=eject%20cd%20group:*.scripting&num=...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Thu, 10 Feb 2005 02:18:10 GMT  
 Eject CD

Quote:

> Is there any way to eject the CD using VbScript?

Hi

Here is a command based util you can use from your vbscript that can open as
well as close the CD-ROM (Close is for NT/2000/XP only)

Wizmo
http://grc.com/wizmo/wizmo.htm

From the docs:

DRIVE OPEN (EJECT) and CLOSE (LOAD)

 open    opens the system's default CDROM drive tray.
Example: wizmo open

 close    closes the system's default CDROM drive tray.
Example: wizmo close

 open={drive:}    open or eject specific removable drive media.
On systems with multiple CDROM or other removable drives (e.g. Iomega Zip and
Jaz) this opens or ejects the media from the specified drive.
Example: wizmo open=w:

 close={drive:}    close or load specific removable drive media.
(NT/2000/XP only) On systems with multiple CDROM or other removable drives (e.g.

Iomega Zip and Jaz) this closes or loads the media on the specified drive. This
function is not available under Windows 95/98/ME. On those systems it will
behave like the "close" function above.
Example: wizmo close=r:

--
torgeir



Fri, 11 Feb 2005 06:06:15 GMT  
 Eject CD
Oh COOL - thanks for sharing this link Torgeir! I've been looking for a
CD-closer (tons of progs can open the dang thing) for what feels like eons.


Quote:
> Here is a command based util you can use from your vbscript that can open
as
> well as close the CD-ROM (Close is for NT/2000/XP only)
> Wizmo
> http://grc.com/wizmo/wizmo.htm



Fri, 11 Feb 2005 22:27:28 GMT  
 Eject CD
"Ned Flanders"

Quote:
> Oh COOL - thanks for sharing this link Torgeir! I've been looking for a
> CD-closer (tons of progs can open the dang thing) for what feels like eons.

Form 2 command buttons

Function Sleep(time)
   Start = Timer
   Do While Timer < Start + time
      DoEvents
   Loop
End Function

Private Sub Form_Load()
SendMCIString "close all", False
cmdClose.Visible = False
If (App.PrevInstance = True) Then
    End
End If
fCDLoaded = False
If (SendMCIString("open cdaudio alias cd wait shareable", True) = False) Then
    End
End If
SendMCIString "set cd time format tmsf wait", True
End Sub

Private Sub Form_Unload(Cancel As Integer)
SendMCIString "close all", False
End Sub
Private Function SendMCIString(cmd As String, fShowError As Boolean) As Boolean
Static rc As Long
Static errStr As String * 200

rc = mciSendString(cmd, 0, 0, hWnd)
If (fShowError And rc <> 0) Then
    mciGetErrorString rc, errStr, Len(errStr)
    MsgBox errStr
End If
SendMCIString = (rc = 0)
End Function
' Open CD
Private Sub cmdopen_Click()
SendMCIString "set cd door open", True
cmdClose.Visible = True
cmdClose.Default = True
Sleep (0.1)
SendKeys "{right}"
cmdOpen.Visible = False
End Sub

Private Sub cmdclose_click()
SendMCIString "set cd door closed", True
cmdOpen.Visible = True
cmdClose.Visible = False
cmdClose.Default = False
cmdOpen.Default = True
Unload Me
End Sub

Module

Option Explicit
Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As
String, ByVal uLength As Long) As Long
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal
lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
--
Fosco



Sun, 13 Feb 2005 00:16:16 GMT  
 Eject CD
Yeah but this does it from command line and I don't have to fire up the
compiler either <g>.
Thanx for the code though - I'm going to put it through VB6 and see if I
don't find a use for it somewhere else.


Quote:
> "Ned Flanders"
> > Oh COOL - thanks for sharing this link Torgeir! I've been looking for a
> > CD-closer (tons of progs can open the dang thing) for what feels like
eons.

> Form 2 command buttons

> Function Sleep(time)
>    Start = Timer
>    Do While Timer < Start + time
>       DoEvents
>    Loop
> End Function

> Private Sub Form_Load()
> SendMCIString "close all", False
> cmdClose.Visible = False
> If (App.PrevInstance = True) Then
>     End
> End If
> fCDLoaded = False
> If (SendMCIString("open cdaudio alias cd wait shareable", True) = False)
Then
>     End
> End If
> SendMCIString "set cd time format tmsf wait", True
> End Sub

> Private Sub Form_Unload(Cancel As Integer)
> SendMCIString "close all", False
> End Sub
> Private Function SendMCIString(cmd As String, fShowError As Boolean) As
Boolean
> Static rc As Long
> Static errStr As String * 200

> rc = mciSendString(cmd, 0, 0, hWnd)
> If (fShowError And rc <> 0) Then
>     mciGetErrorString rc, errStr, Len(errStr)
>     MsgBox errStr
> End If
> SendMCIString = (rc = 0)
> End Function
> ' Open CD
> Private Sub cmdopen_Click()
> SendMCIString "set cd door open", True
> cmdClose.Visible = True
> cmdClose.Default = True
> Sleep (0.1)
> SendKeys "{right}"
> cmdOpen.Visible = False
> End Sub

> Private Sub cmdclose_click()
> SendMCIString "set cd door closed", True
> cmdOpen.Visible = True
> cmdClose.Visible = False
> cmdClose.Default = False
> cmdOpen.Default = True
> Unload Me
> End Sub

> Module

> Option Explicit
> Declare Function mciGetErrorString Lib "winmm.dll" Alias

"mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As
Quote:
> String, ByVal uLength As Long) As Long
> Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA"

(ByVal lpstrCommand As String, ByVal
Quote:
> lpstrReturnString As String, ByVal uReturnLength As Long, ByVal

hwndCallback As Long) As Long

- Show quoted text -

Quote:
> --
> Fosco



Sun, 13 Feb 2005 00:29:39 GMT  
 Eject CD
This is air code right?  The line:
rc = mciSendString(cmd, 0, 0, hWnd)
gives me an error that hWnd is not defined anywhere.  What's it's value
supposed to be?


Quote:
> Form 2 command buttons



Sun, 13 Feb 2005 00:39:34 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Eject CD in case of 2 CD drives

2. EJECT CD from CD Drive ???

3. Load and Eject CD-Tray

4. Ejecting CD's from BASIC?

5. Ejecting CD Tray

6. API to eject cd-rom-drive?

7. Eject CD?

8. Code for eject CD

9. Eject CD?

10. Autoplay enable/disable, Eject CD

11. Ejecting CD from drive

12. Eject Cd-rom (Again!)

 

 
Powered by phpBB® Forum Software