Code : Tout sélectionner
#REMOVABLE_DRIVE = 1
#FIXED_DRIVE = 2
#REMOTE_DRIVE = 4
#CDROM_DRIVE = 8
#RAMDISK_DRIVE = 16
#UNKNOWN_DRIVE = 32
#ALL_DRIVE = 63
Procedure FindUsbKey()
Drive.l = GetLogicalDrives_()
Bit.l = 1
For n = 3 To 26
If (Drive & Bit) <> 0
DriveLetter.s = Chr(64 + n)
DriveType.l = GetDriveType_(DriveLetter + ":\")
If DriveType = #DRIVE_REMOVABLE
ProcedureReturn #True
EndIf
EndIf
Bit = Bit * 2
Next
ProcedureReturn #False
EndProcedure
Procedure ProcedureCallback(WindowID, Message, wParam, lParam)
Resultat = #PB_ProcessPureBasicEvents
Select Message
Case #WM_QUERYENDSESSION
If FindUsbKey()
MessageRequester("Attention","Votre clé USB est toujours branchée sur ce PC."+Chr(13)+Chr(10)+"N'oubliez pas de la débrancher !",#MB_ICONWARNING)
EndIf
ProcedureReturn #True
EndSelect
ProcedureReturn Resultat
EndProcedure
If OpenWindow(0,0,0,400,400,#PB_Window_Invisible | #PB_Window_ScreenCentered,"CléUSB Detector")
SetWindowCallback(@ProcedureCallback())
Repeat
EventID.l=WaitWindowEvent()
Select EventID
Case #WM_CLOSE
Quit=1
EndSelect
Until Quit=1
EndIf
End