Posts: 1,769
Threads: 410
Joined: Feb 2003
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?
Posts: 1,271
Threads: 399
Joined: Mar 2003
i use function getdrivestatus:
Drive status
Posts: 1,769
Threads: 410
Joined: Feb 2003
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.
Posts: 1,271
Threads: 399
Joined: Mar 2003
you could start a function with tim in init2
like:
tim 3 usb_checker
Posts: 1,769
Threads: 410
Joined: Feb 2003
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
Posts: 12,061
Threads: 140
Joined: Dec 2002
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.
;/
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"
,,
Posts: 1,769
Threads: 410
Joined: Feb 2003
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.
if WINAPI.GetDriveType("e:\")=2
do this stuff
Posts: 1,058
Threads: 367
Joined: Oct 2007
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
Posts: 12,061
Threads: 140
Joined: Dec 2002
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.
Posts: 1,058
Threads: 367
Joined: Oct 2007
It is a very clear explanation. Many thanks indeed.
Posts: 1,058
Threads: 367
Joined: Oct 2007
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.