La Web del Programador: Comunidad de Programadores
 
    Pregunta:  44080 - ¿CÓMO PUEDO DETECTAR LAS UNIDADES DE CD/DVD?
Autor:  Paco
Hola

Me gustaría detectar las unidades de CD o de DVD, es decir las API'S

Gracias...

  Respuesta:  SuNcO
Pues.. como no tengo unidad de Dvd.. al menos aqu iesta para detectar el CD.. supongo con algunas modificaciones se puede detectar el del DVD

Se ocupa un CommandButton y un TextBox

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Sub Command1_Click()
Text1.Text = FindCDROM
End Sub
Function FindCDROM() As String
Dim Drive As Integer
Const DRIVE_CDROM = 5
FindCDROM = "No hay CD_ROM Instalado"

For Drive = 65 To 90
If GetDriveType(Chr(Drive) & ":\") = DRIVE_CDROM Then
FindCDROM = "CD-ROM Drive " & Chr(Drive) & ":\"
Exit For
End If
Next Drive
End Function

  Respuesta:  Darinel Cancino G.
Mira amigo puedes hacerlo de la siguiente manera, Sigue los siguientes pasos, espero te sirva de algo.

1. Crear un proyecto nuevo en Visual Basic, por defecto será Form1
2. Añadir el siguiente codigo a formulario en General Declarations.

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

3. Añadir un control Command Button al Form1
4. Añadir el siguiente codigo al evento Click de Command Button

Private Sub Command1_Click()
Text1.Text = FindCDROM
End Sub

5. Añadir un control Text Box al Form1.
En propiedades "Multiline" fijar "true"
6. Crear una función llamada FindCDROM y añadir el siguiente codigo:

Function FindCDROM() As String
Dim Drive As Integer
Const DRIVE_CDROM = 5
FindCDROM = "No hay CD_ROM Instalado"
For Drive = 65 To 90
If GetDriveType(Chr(Drive) & ":\") = DRIVE_CDROM Then
FindCDROM = "CD-ROM Drive " & Chr(Drive) & ":\"
Exit For
End If
Next Drive
End Function