Ciao ho un dubbio come posso far si che un programma che si avvia appena il CD viene inserito (autorun!) si chiuda in automatico non appena questo viene estratto
Ciao ho un dubbio come posso far si che un programma che si avvia appena il CD viene inserito (autorun!) si chiuda in automatico non appena questo viene estratto
dovresti scaricarti un ocx ke permette di rilevare la presenza dell'unità o + semplicemente mandare un ciclo con un timer ke ogni 30 sec prova a leggere un file sul cd, se va in errore, chiude il prog :metallica
Il 90% dei problemi di un pc si trova
tra la tastiera e la sedia.
Come faccio a sapere qual'è la lettera che indentifica il lettore CD? normalmente è la D: ma se uno ha più partizioni può essere qualsiasi
Il programma che parte in autorun conosce sicuramente il percorso di partenza (App.Path) che potresti utilizzare per estrarre il nome dell'unità cdrom.
Chi non cerca trova.
Tramite API
private Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (byval nDrive as string) as Long
private Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" (byval nBufferLength as Long, _
byval lpBuffer as string) as Long
private Const DRIVE_CDROM = 5
private Sub ListCDROMs()
Dim sDrives as string
Dim sDrive as string
sDrives = Space(255)
sDrives = Left$(sDrives, GetLogicalDriveStrings(255, byval sDrives))
While InStr(sDrives, "\")
sDrive = Left$(sDrives, InStr(sDrives, "\"))
If GetDriveType(sDrive) = DRIVE_CDROM then
Debug.Print "(CDRom) " & sDrive
End If
sDrives = mid$(sDrives, len(sDrive) + 2)
Wend
End Sub
Tramite FileSystemObject
Dim fso As New Scripting.FileSystemObject
Dim drv As Drive
For Each drv In fso.Drives
If drv.DriveType = CDRom Then
CDPath = drv.Path
Exit For
End If
Next drv
Set drv = Nothing
Set fso = Nothing
Per sapere se un cd è o non è nel lettore beh windows passa il messaggio WM_DEVICECHANGE quando avviene qualcosa, quindi dovresti intercettarlo e gestirlo (subclassing).
Guarda questo esempio.
http://www.allapi.net/php/redirect/r...ownload&id=368
Ans.
ok, conviene fare così!![]()
Il 90% dei problemi di un pc si trova
tra la tastiera e la sedia.