;/ Droopy 28/11/05
; Return 1 if a Removable Media is detected ( Probably a USB Key ) / 0 instead
Procedure DetectUSBKey()
For n=2 To 26
If Realdrivetype_(n,0)= #DRIVE_REMOVABLE
ProcedureReturn 1
EndIf
Next
EndProcedure
;/ Test
If DetectUSBKey()
MessageRequester("Removable Drive","Present",#MB_ICONINFORMATION)
Else
MessageRequester("Removable Drive","Absent",#MB_ICONERROR )
EndIf
Thanks, here's some similar snippets, used to detect a removable disk type digital camera. FindCamera()
checks the drives for a #DRIVE_REMOVABLE type disk.
;Used by GetDeviceEvent()
#WM_DEVICECHANGE = $219
#DBT_DEVICEARRIVAL = $8000 ;A device has been inserted
#DBT_DEVICEREMOVECOMPLETE = $8004 ;A device has been removed.
.
.
.
;Set a callback to handle removable device events
SetWindowCallback(@GetDeviceEvent())
.
.
.
Procedure GetDeviceEvent(WindowID, Message, wParam, lParam)
;Callback procedure to handle camera connect/disconnect events
Result = #PB_ProcessPureBasicEvents
If Message = #WM_DEVICECHANGE
Select wParam
Case #DBT_DEVICEARRIVAL
;Removable device inserted
;Detect a camera
If FindCamera()
;Camera detected
;
Else
;Camera not connected
EndIf
Case #DBT_DEVICEREMOVECOMPLETE
;Removable device removed
If FindCamera() = 0
;Camera not found
EndIf
EndSelect
EndIf
ProcedureReturn Result
EndProcedure
Sorry I am having a problem, the program returns "Present" even if I have OR don't have a USB Key plugged.
I checked all my USB ports and none of them has a USB Key plugged, when I ran the code it returned "Present". Then I tested to insert a USB Key in one of my USB ports and the program still outputs "Present"
josku_x wrote:Sorry I am having a problem, the program returns "Present" even if I have OR don't have a USB Key plugged.
I checked all my USB ports and none of them has a USB Key plugged, when I ran the code it returned "Present". Then I tested to insert a USB Key in one of my USB ports and the program still outputs "Present"
;/ Droopy 28/11/05
; Return 1 if a Removable Media is detected ( Probably a USB Key ) / 0 instead
Procedure DetectUSBKey()
For n=2 To 26
If Realdrivetype_(n,0)= #DRIVE_REMOVABLE
Debug Chr(n+65)+": Drive is a Removable Drive"
ProcedureReturn 1
EndIf
Next
EndProcedure
;/ Test
If DetectUSBKey()
MessageRequester("Removable Drive","Present",#MB_ICONINFORMATION)
Else
MessageRequester("Removable Drive","Absent",#MB_ICONERROR )
EndIf