|
-
Feb 17th, 2007, 01:54 PM
#1
Thread Starter
Hyperactive Member
Opening The CD Rom Drive
does anyone know how to make the software automatically open a specific cd rom drive?
if you happen to know a string of code that does this, it would be appreciated...
-
Feb 17th, 2007, 02:04 PM
#2
Addicted Member
Re: Opening The CD Rom Drive
in vb 6.0 you would use API try it...
VB Code:
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
Private Sub cmdOpenCD_Click()
Dim lRet As Long
lRet = mciSendString("set CDAudio door open", returnstring, 127, 0)
End Sub
Private Sub cmdCloseCD_Click()
Dim lRet As Long
lRet = mciSendString("set CDAudio door closed", returnstring, 127, 0)
End Sub
-
Feb 17th, 2007, 02:59 PM
#3
Thread Starter
Hyperactive Member
Re: Opening The CD Rom Drive
that one didn't work, but thanks... if anyone else has one i can try i'd appreciate it...
-
Feb 17th, 2007, 03:10 PM
#4
Re: Opening The CD Rom Drive
It is working but you have to change every Long there to Integer and put the Returnstring in "":
VB Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
'then to open:
Dim lRet As Long
lRet = mciSendString("set CDAudio door open", "returnstring", 127, 0)
'and to close:
Dim lRet2 As Long
lRet2 = mciSendString("set CDAudio door closed", "returnstring", 127, 0)
Shoutouts go to Genom of course.
-
Feb 17th, 2007, 03:20 PM
#5
Thread Starter
Hyperactive Member
Re: Opening The CD Rom Drive
that didn't work for me either... do i install that on a button or will it do it automatically?
i'm a noob... so i need some help... i never would have figured out any of that so far...
-
Feb 17th, 2007, 03:23 PM
#6
Re: Opening The CD Rom Drive
Yes, the 'Private Declare Function etc...' is outside any procedure, then put
VB Code:
Dim lRet As Long
lRet = mciSendString("set CDAudio door open", "returnstring", 127, 0)
in a button click.
-
Feb 17th, 2007, 06:56 PM
#7
Addicted Member
Re: Opening The CD Rom Drive
only for info
VB Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
is a declaration of a function which shows to software that there is a function in that dll file and make it ready to use. we put them always outside an event or a function.
-
Feb 17th, 2007, 08:57 PM
#8
Thread Starter
Hyperactive Member
Re: Opening The CD Rom Drive
ok, i got the string in with no errors, but when i click the button... nothing happens...
-
Jul 26th, 2007, 08:16 AM
#9
Fanatic Member
Re: Opening The CD Rom Drive
hi Conflix
I Need The Same Thing As You
Have You Sorted ?
Plz Post The Working One
Thanks
-
Jul 26th, 2007, 11:54 AM
#10
Re: Opening The CD Rom Drive
Here is a complete example:
Opens the CD tray and then after 2 seconds it closes too.
Code:
Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("winmm.dll", CharSet:=CharSet.Auto, EntryPoint:="mciSendString")> _
Private Shared Function mciSendString( _
ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, _
ByVal uReturnLength As Integer, _
ByVal hwndCallback As Integer) As Integer
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lRet As Long
lRet = mciSendString("set CDAudio door open", "returnstring", 127, 0)
System.Threading.Thread.Sleep(2000)
lRet = mciSendString("set CDAudio door closed", "returnstring", 127, 0)
End Sub
End Class
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 26th, 2007, 02:39 PM
#11
Re: Opening The CD Rom Drive
Here is a sub to open a specific CDRom tray using Window Media Player. You need to add a reference to Windows Media Player COM object to your project
Code:
Imports WMPLib
Private Sub EjectCDRom(ByVal driveName As String)
Dim player As WMPLib.WindowsMediaPlayer = Nothing
Try
player = New WMPLib.WindowsMediaPlayer
Dim count As Integer = player.cdromCollection.count
If count > 0 Then
For n As Integer = 0 To count - 1
If (player.cdromCollection.Item(n).driveSpecifier).StartsWith(driveName.ToUpper) Then
player.cdromCollection.Item(n).eject()
Exit For
End If
Next
End If
Catch ex As Exception
Throw ex
Finally
player = Nothing
End Try
End Sub
For example, if you want to open the tray of the E: CDRom drive, you just call
-
Jul 26th, 2007, 07:47 PM
#12
Fanatic Member
Re: Opening The CD Rom Drive
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|