?
Solved

eject a CD with vbs

Posted on 2003-03-26
8
Medium Priority
?
769 Views
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
0
Comment
Question by:Alderaic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 

Expert Comment

by:MoDrop
ID: 8213045
Try...


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&)
    Else
        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
-MoDrop
0
 

Expert Comment

by:MoDrop
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.
-MoDrop
0
 

Author Comment

by:Alderaic
ID: 8213080
this indeed works fine in a vb form but not in vbs , any ideas ? :-/
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Alderaic
ID: 8213097
(the wmi point is because the computer holding the cd is on the network )
0
 
LVL 1

Expert Comment

by:VB-Expert
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
        colCDROMs.Item(i).Eject
    Next  ' cdrom
End If



''VB-Expert
0
 

Author Comment

by:Alderaic
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
0
 
LVL 1

Accepted Solution

by:
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"

'VB-Expert
0
 

Author Comment

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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 Month13 days, 10 hours left to enroll

801 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