My latest project involves USB Drives. I am trying to write a script that, while running on the computer, can detect when a USB drive is inserted, and automatically backup my files off of it (given the Label matches). I've gotten a good bit of the code figured out, but I'm stuck. I was wondering if anyone could help me.
Here's the code I have so far:
$DBT_DEVICEARRIVAL = "0x00008000" $WM_DEVICECHANGE = 0x0219 GUICreate("") GUIRegisterMsg($WM_DEVICECHANGE , "MyFunc") Func MyFunc($hWndGUI, $MsgID, $WParam, $LParam) If $WParam == $DBT_DEVICEARRIVAL Then ; Find newly inserted Drive here, test for correct label, and then backup files from it EndIf EndFunc While 1 $GuiMsg = GUIGetMsg() WEnd
It can successfully detect whenever a new Device is inserted into the computer just fine, there's just 2 problems with it so far:
1. It can't tell the difference between a newly inserted CD and a newly inserted USB drive, which is not good, as I would like for it to only trigger on USBs
2. Even though it can detect that something was inserted, it can't find the drive in question (by Letter, I mean). I could make a function that, whenever something was inserted, compare it to a list of drives before the insertion, and the difference has to be my new drive, but that's ugly, and also means I'd have to investigate as to detecting when drives were removed to keep my list clean.
From all of my readings and Googling, all I can come up with is that the $LParam has something to do with what kind of drive is being inserted, and where it might be located (as per this article). But, I can't seem to detect the differences with what I have so far.
If anyone can help me, I would greatly appreciate it. Thanks for any help you provide me.