Les Snippets

Connexion

Ejecter les CD ou DVD des lecteurs CDRom ou DVDRom

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 06/04/2006 11:58:39 et initié par bultez [Liste]
Date de mise à jour : 07/12/2008 17:36:02
Vue : 20644
Catégorie(s) : Trucs & Astuces
Langages dispo pour ce code :
- Javascript
- VB6
- C# 1.x, C# 2.x
- VB 2005, VB.NET 1.x
- VB6, VBA



Langage : Javascript
Date ajout : 06/04/2006
Posté par bultez [Liste]
DateMAJ : 06/04/2006
<script type="text/javascript">
 var WMP = new ActiveXObject("WMPlayer.OCX" );
 for ( n = 0; n < WMP.cdromCollection.Count; n++ )
 {
  WMP.cdromCollection.Item(n).Eject();
 }
 opener=self;
 window.close();
</script>

Remarque :
Exclusif Windows + Internet Explorer,
à copier/coller vers un .HTA
Langage : VB6
Date ajout : 06/04/2006
Posté par bultez [Liste]
DateMAJ : 06/04/2006
Private Sub Form_Load()
    ' avec le composant WindowsMediaPlayer
    Dim n As Integer
    For n = 0 To WMP.cdromCollection.Count - 1
        WMP.cdromCollection.Item(n).eject
    Next n
    Unload Me
End Sub

Langage : C# 1.x , C# 2.x
Date ajout : 08/04/2006
Posté par Bidou [Liste]
DateMAJ : 03/09/2006

public class MediaROM 
{
   [DllImport("winmm.dll", EntryPoint = "mciSendStringA")] 
   private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

   public static void OpenDoor(char driveLetter) 
   {
      MediaROM.mciSendString(string.Format("set CDAudio!{0} door open", driveLetter), null, 127, 0); 
   }
   public static void CloseDoor(char driveLetter) 
   {
      MediaROM.mciSendString(string.Format("set CDAudio!{0} door closed", driveLetter), null, 127, 0); 
   }
}


// Utilisation
MediaROM.OpenDoor('F'); 
MediaROM.CloseDoor('F');




Langage : VB.NET 1.x , VB 2005
Date ajout : 09/04/2006
Posté par archimed111 [Liste]
    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

''On charge la DLL
    Private Sub OuvrirLecteur(ByVal lecteur As String)
        mciSendString(String.Format("set CDAudio!{0} door open", lecteur), Nothing, 127, 0)
    End Sub
'' Pour ouvrir la lecteur E: par exemple :
'' OuvrirLecteur("E:")
Langage : VB6 , VBA
Date ajout : 07/12/2008
Posté par PCPT [Liste]
DateMAJ : 07/12/2008
Private Const INVALID_HANDLE_VALUE      As Long  = -1
Private Const OPEN_EXISTING             As Long  = 3
Private Const FILE_FLAG_DELETE_ON_CLOSE As Long  = 67108864
Private Const GENERIC_READ              As Long  = &H80000000
Private Const GENERIC_WRITE             As Long  = &H40000000
Private Const IOCTL_STORAGE_EJECT_MEDIA As Long  = 2967560
Private Const VWIN32_DIOC_DOS_IOCTL     As Long  = 1
'
Private Type DIOC_REGISTERS
  reg_EBX   As Long
  reg_EDX   As Long
  reg_ECX   As Long
  reg_EAX   As Long
  reg_EDI   As Long
  reg_ESI   As Long
  reg_Flags As Long
End Type
'
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As LongAs Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As StringByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes  As Any, ByVal dwCreationDisposition  As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As  Long
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As LongByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, lpOverlapped As Any) As  Long
Private Declare Function GetVersion Lib "kernel32" () As Long
'
'
Public Sub EjectDrive(ByVal sLetter As String)
    Dim hDrive              As Long
    Dim DummyReturnedBytes  As Long
    Dim RawStuff            As DIOC_REGISTERS
        
'    nettoyage lettre
    sLetter = GetValideDriveLetter(sLetter)
    
    If LenB(sLetter) Then
        If GetVersion >= Then 'We are running Windows  NT/2000
            hDrive = CreateFile("\\.\" & sLetter, GENERIC_READ Or GENERIC_WRITE, 0, ByVal  0, OPEN_EXISTING,  0, 0)
            If hDrive <> INVALID_HANDLE_VALUE  Then
                'Eject media!
                Call DeviceIoControl(hDrive,  IOCTL_STORAGE_EJECT_MEDIA, 0, 0,  0, 0, DummyReturnedBytes, ByVal 0)
                Call CloseHandle(hDrive)  'Clean up after  ourselves
            End If
        Else  'We are running Win9x/Me
            hDrive = CreateFile("\\.\VWIN32"00ByVal 00, FILE_FLAG_DELETE_ON_CLOSE, 0)
            If hDrive <> INVALID_HANDLE_VALUE  Then
                'Setup our raw registers to use Interrupt 21h  Function 440Dh Minor Code 49h
                RawStuff.reg_EAX = &H440D  'The function to use
                RawStuff.reg_EBX = Asc(sLetter) - Asc("A") + 'The  drive to do it on
                RawStuff.reg_ECX = &H49 Or &H800 'The minor code of the  function in the low byte of the low word and the device category of 8 in the  high byte of the low word
                'Eject  media!
                Call DeviceIoControl(hDrive, VWIN32_DIOC_DOS_IOCTL, RawStuff,  LenB(RawStuff), RawStuff,  LenB(RawStuff),  DummyReturnedBytes, ByVal 0)
                Call CloseHandle(hDrive)  'Clean up after ourselves
            End If
        End If
    End If
End Sub
Public Function GetValideDriveLetter(ByVal sLetter As String) As String
    sLetter = UCase$(LeftB$(Trim$(sLetter), 2))
    If sLetter Like "[A-Z]" Then GetValideDriveLetter = sLetter & ":"
End Function

Remarque :
repris (à peine modifié) depuis l'API-Guid

Snippets en rapport avec : Cdrom, Dvdrom, Éjection, Ouverture, Eject



Codes sources en rapport avec : Cdrom, Dvdrom, Éjection, Ouverture, Eject

{JAVA / J2EE} EJECTER / FERMER CD-ROM / DVD-ROM (JNI + WINDOWS)
Contrôler votre CD-ROM / DVD-ROM. Comme Java ne dispose pas de fonctions de bas-niveau pour contrôl...

{Visual Basic, VB6, VB.NET, VB 2005} TEST LECTEUR CD OU DVD OUVERT OU FERMÉ
Ce code teste l'état du lecteur Cd ou DVD sélectionné et indique si le lecteur est ouvert ou fermé.C...

{Visual Basic, VB6, VB.NET, VB 2005} CDROM (OUVERTURE, FERMETURE MULTI CD)
Ce code permet d'ouvrir ou de fermer le lecteur CD de votre choix, pour ceux qui comme moi possède a...

{C# / C#.NET} PROJET EDUCATIF : CD INTERACTIF DU PROJET PUISSANCE QUATRE.
C'est un cd interactif, une application qui sert a presenter un projet, ou autre chose. l'animation ...

{Visual Basic, VB6, VB.NET, VB 2005} SIMULATION D'UNE CONNEXION NETBUS
Ce programme ouvre en fait les ports de NetBus (je sais bien que c'est pas très dur de le faire même...

{JAVA / J2EE} FILECHOOSER MODE OUVERTURE SIMPLIFIÉ
Permet de simplifier légèrement l'appel à JFileChooser dans le but de sélectionner un fichier à ouvr...

{C / C++ / C++.NET} ANIMER L'OUVERTURE ET LA FERMETURE D'UNE FENETRE (WIN32 - DEVC++)
Voici une petite astuce pour animer l'ouverture et la fermeture d'une fenetre. J'ai utilisé la fonct...

{Visual Basic, VB6, VB.NET, VB 2005} OUVRIR DES HTA SANS MESSAGE DE LA PART DE WINDOWS
Lorsque l'on essaie d'ouvrir un fichier a partir d'un hta, window (IE version6.00.2900 et +) nous ...

{C / C++ / C++.NET} CRÉER UN FICHIER ISO À PARTIR D'UN RÉPERTOIRE (WIN32)
Après l'explorateur de fichier ISO, voici un code permettant de créer un fichier ISO à partir d'un r...

{C / C++ / C++.NET} EXPLORATEUR DE FICHIERS ISO
Après mon code permettant de faire un fichiers ISO d'un cd-rom (http://www.cppfrance.com/code.aspx?I...