
pb4-code (bei pb3 GetFunction durch IsFunction ersetzen !)
Code: Alles auswählen
#DIGCF_PRESENT = 2
#DIGCF_ALLCLASSES = 4
hDeviceInfoSet = SetupDiGetClassDevs_(0,0,0,#DIGCF_PRESENT|#DIGCF_ALLCLASSES)
Structure SP_DEVINFO_DATA
cbSize.l
ClassGuid.GUID
DevInst.l
Reserved.l
EndStructure
Global DeviceInfoData.SP_DEVINFO_DATA ;global für funktion
DeviceInfoData\cbSize=SizeOf(DeviceInfoData)
#SPDRP_SERVICE = 4
*MemoryID = AllocateMemory(500)
i.l
OpenLibrary(1,"setupapi.dll")
*F1 = GetFunction(1, "SetupDiGetDeviceInstanceIdA")
*F2 = GetFunction(1, "SetupDiGetDeviceRegistryPropertyA")
*F3 = GetFunction(1, "CM_Locate_DevNodeA")
*F4 = GetFunction(1, "CM_Request_Device_Eject_ExA")
While SetupDiEnumDeviceInfo_(hDeviceInfoSet,i,@DeviceInfoData)
i+1
CallFunctionFast(*F2,hDeviceInfoSet,DeviceInfoData,#SPDRP_SERVICE,0,*MemoryID,500,0)
If UCase(PeekS(*MemoryID)) = "USBSTOR"
CallFunctionFast(*F1,hDeviceInfoSet,DeviceInfoData,*MemoryID,500,0)
If CallFunctionFast(*F3,@devinst.l,PeekS(*MemoryID),0) = 0
CallFunctionFast(*F4,devinst,0,0,0,0,0)
EndIf
EndIf
Wend
SetupDiDestroyDeviceInfoList_(hDeviceInfoSet)
CloseLibrary(1)
FreeMemory(*MemoryID)