Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


eject a CD with vbs

Posted on 2003-03-26
Medium Priority
Last Modified: 2008-02-01
I need to eject a specific CD-Drive using WMI if possible.
and I dont have windows media player installed so this ocx trick doesnt work.
any solutions to do this ?

(using a shellexec inside the vbs is ok but only if it works for win2k and XP )

thanks in advance
Question by:Alderaic
  • 4
  • 2
  • 2

Expert Comment

ID: 8213045

Private 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

Public Sub SetCDState(pbState As Boolean)
    If pbState Then
        Call mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
        Call mciSendString("Set CDAudio Door Closed", 0&, 0&, 0&)
    End If
End Sub

... Just Call The Sub With True To Open And False To Close

Expert Comment

ID: 8213058
Oh I Didn't Quite Read "specific" So I Don't Know If That Will Get The Right One. I'm Not Sure On The Functions Total Properties But You May Have To Tinker Around To Get It To Work For You.

Author Comment

ID: 8213080
this indeed works fine in a vb form but not in vbs , any ideas ? :-/
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 8213097
(the wmi point is because the computer holding the cd is on the network )

Expert Comment

ID: 8215555
Try the following

' Needs Windows Media Player installed

Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection

if colCDROMs.Count >= 1 then
    For i = 0 to colCDROMs.Count - 1
    Next  ' cdrom
End If


Author Comment

ID: 8215569
hehe as I said before the media player trick is not an option for me boxes are installed with minimal stuff and all extra is removed

anyway if I dont find anything else I will go that way

Accepted Solution

VB-Expert earned 200 total points
ID: 8215765
'Alternative mathod without media player

'AS mentioned above, (using a shellexec inside the vbs is ok but only if it works for win2k and XP)
'This maybe what you are looking for.

 'Try this,

'Note: the CD drive cannot be close using the (Shell.Application) technique.

    Const ssfDRIVES = &H11  ' namespace constant (drives folder = 17)...
    Const cdromDrvLtr = "G:\"  ' specify your cd-rom drive letter...
      Set oSH = CreateObject("Shell.Application")
      ' open the cd-rom drawer...
      oSH.NameSpace(ssfDRIVES).ParseName(cdromDrvLtr).InvokeVerb "E&ject"


Author Comment

ID: 8215779
exactly what I was looking for :) thanks a lot

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question