Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy a Flash Drive
#2
Function NewDriveWatcher
Code:
Copy      Help
function# hWnd message wParam lParam
if(hWnd) goto messages

;New drive watcher function.
;Run it. It runs all the time until QM exits. If you run it again (while already running), you can end it.
;Whenever it gets a notification that a new removable drive inserted, it launches function NewDriveInserted. Edit it.
;Works with flash drives/cards and CD/DVD. Does not work with floppy. Gets drive type and other info in NewDriveInserted.


if(getopt(nthreads)>1)
,if(mes("The function is already running. Do you want to end it?" "QM - NewDriveWatcher" "YN?")='Y') shutdown -6 0 "NewDriveWatcher"
,ret

hWnd=CreateWindowEx(0 "#32770" 0 WS_POPUP 0 0 0 0 0 0 _hinst 0)
int- wp=SubclassWindow(hWnd &NewDriveWatcher)
MessageLoop
ret

;messages
sel message
,case WM_DEVICECHANGE
,sel wParam
,,case DBT_DEVICEARRIVAL
,,NDW_Arrival +lParam

ret CallWindowProc(wp hWnd message wParam lParam)

Function NDW_Arrival
Code:
Copy      Help
;/NewDriveWatcher
function DEV_BROADCAST_HDR*hdr

if(hdr.dbch_devicetype!=DBT_DEVTYP_VOLUME) ret
DEV_BROADCAST_VOLUME* v=+hdr
if(v.dbcv_flags&DBTF_NET) ret
;out "0x%X 0x%X" v.dbcv_unitmask v.dbcv_flags

str sd=" :\"
int i m=v.dbcv_unitmask
for i 0 32
,if(m&1)
,,sd[0]='A'+i
,,mac "NewDriveInserted" "" sd
,m>>1

Function NewDriveInserted
Code:
Copy      Help
;\
function str'drive

Wsh.Drive d=GetDrive(drive)

;out drive
;out d.DriveType
;out d.IsReady

sel d.DriveType
,case 1 ;;flash
,
,case 4 ;;CD
,ret
,
,case else ;;should never be
,ret


;add your flash drive copying code here.
;example:

str n=d.VolumeName; if(n.len) n.fix(50 2); n-" ("; n+")"
str dest.from("$desktop$\flash drives\" d.SerialNumber n)
out "<>Copying <link>%s</link> to %s[]Please wait..." drive dest
cop _s.from(drive "*") dest 0x2C0~FOF_FILESONLY
err out _error.description; ret
out "<>Finished copying  <link>%s</link> to <link>%s</link>" drive dest

;note: several drives can be copied simultaneously


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)