Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy a Flash Drive
#1
What I am trying to do is have QM copy the entire contents of a flash drive any time a flash drive is plugged in. How do i set up the event of a flash drive being plugged in as the trigger? And how do i have QM determine the drive letter and copy the contents of the flash drive to a specified directory. What happens is, is that i have one workstation devoted to copying multiple flash drives. All the contents of all of the drives go to the same location. I would like for QM to automate this so that the person running the workstation only has to plug in the drive to make this happen.
#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
#3
Thanks so much for this. This has been extremely useful. I have one more question about this though. If i wanted to have this automatically start when the computer was logged on to, could i just make an exe with all of the functions in it and place that exe into the startup folder? Would that work?
#4
Yes. Example:
Function copy_new_drive
Code:
Copy      Help
;/exe
SetLastError 0
__Handle m=CreateMutex(0 1 "mutex_copy_new_drive")
if(!m) mes- "Error"
if(GetLastError=ERROR_ALREADY_EXISTS)
,if(mes("copy_new_drive already running. Do you want to end it?" "copy_new_drive" "YN?")='Y')
,,ShutDownProcess "copy_new_drive" 16 ;;this should end the older process, but need more testing
,mes 1
,ret

NewDriveWatcher 0 0 0 0

;BEGIN PROJECT
;main_function  copy_new_drive
;exe_file  $desktop$\copy_new_drive.exe
;icon  <default>
;manifest  $qm$\default.exe.manifest
;res  
;on_before  
;on_after  
;on_run  
;flags  6
;end_hotkey  0
;guid  {4C0516F5-0C9A-4BCE-9212-2F5CE04F4CFD}
;END PROJECT


Forum Jump:


Users browsing this thread: 1 Guest(s)