Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
USB drive
#1
Is there a way to monitor when a USB drive shows up?
I'm looking for anything at all to trigger off of. the file triggers dont seem to start monitoring untill after the files show up on the system rather than when the files show up.

thanks.


if not, is there a way to have a thumb drive do a sort of autorun like a cd?
An old blog on QM coding and automation.

The Macro Hook
#2
i use function getdrivestatus:
Drive status
pi
#3
does this sit and wait for a drive insertion trigger and then start? it looks like you have to run it after the drive is inserted to get the drivetype.
An old blog on QM coding and automation.

The Macro Hook
#4
you could start a function with tim in init2
like:
tim 3 usb_checker
pi
#5
that's a great idea if there isn't a way to hook into the system and use the trigger.

would there be something in here about it? it's pretty far over my head but you can probably make sense of it.

http://msdn.microsoft.com/library/defau ... ft05a1.asp
An old blog on QM coding and automation.

The Macro Hook
#6
Assign this toolbar hook function to a toolbar that is open all time and it will notify when a drive is inserted and removed. Also works with CD and other. Function name is not important.

Code:
Copy      Help
;/
function# hWnd message wParam lParam

def WM_DEVICECHANGE  0x219
def DBT_DEVICEARRIVAL 0x8000
def DBT_DEVICEREMOVECOMPLETE  0x8004
def DBT_DEVTYP_VOLUME 0x2

type DEV_BROADCAST_VOLUME dbcv_size dbcv_devicetype dbcv_reserved dbcv_unitmask @dbcv_flags

sel message
,case WM_DEVICECHANGE
,sel(wParam) case [DBT_DEVICEARRIVAL,DBT_DEVICEREMOVECOMPLETE] case else ret
,DEV_BROADCAST_VOLUME* v=+lParam
,if(v.dbcv_devicetype!=DBT_DEVTYP_VOLUME) ret
,int i j=v.dbcv_unitmask
,for(i 0 26) if(j&1) break; else j>>1
,i+'A'
,sel wParam
,,case DBT_DEVICEARRIVAL
,,out "inserted %c" i
,,;if(i='E') mac "OnInserted"
,,
,,case DBT_DEVICEREMOVECOMPLETE
,,out "removed %c" i
,,;if(i='E') mac "OnRemoved"
,,
#7
WOW! that's really nice.

i also got it to trigger off of "rundll32" process and check to make sure it was actually the drive that started it up.

Code:
Copy      Help
if WINAPI.GetDriveType("e:\")=2
do this stuff
An old blog on QM coding and automation.

The Macro Hook
#8
Dear Gintaras,

I am using this toolbar hook function for a couple of years successfully. Neverthless, I am afraid I have not understood the way that a toolbar which is open all time can trigger this hook function. More specifically, is this function running continiously or on a special event? What forces a device broadcast signal to trigger a toolbar, which then it triggers its hook function. I would appreciate any advice if possible, at your convenience.

Regards
#9
For this trigger we need a window, because OS sends WM_DEVICECHANGE message to all windows. It can be a dialog, or a toolbar, or other window, and it must exist all time. In this example I used toolbar, to avoid creating new thread. A toolbar hook function works like a window or dialog procedure. It is called every time when the toolbar receives a message.
#10
It is a very clear explanation. Many thanks indeed.
#11
Dear Gintaras,

Is it possible to extend this routine in the case of a portable media device, such as a Nokia E7-00 phone. I need to access its mass memory.

Thanks in advance.


Sorry for bothering : I had only to change a phone's internal setting in order to behave as USB device.


Forum Jump:


Users browsing this thread: 1 Guest(s)