Hamcher Posted February 19 Share Posted February 19 Hey all, this is my first time posting and I have had a little look around to see if I could find my issue before posting. I am writing a script to detect when a drive (specific drive letter) is mounted, then run a file on that drive. Currently I am using the USB mounting detection but that doesn't detect when a CF card is inserted into my reader, it only detects when I unplug the reader (with the card in it) then plug it back in. Below is my current code: $DBT_DEVICEARRIVAL = "0x00008000" $WM_DEVICECHANGE = 0x0219 GUICreate("") GUIRegisterMsg($WM_DEVICECHANGE , "MyFunc") Func MyFunc($hWndGUI, $MsgID, $WParam, $LParam) If $WParam == $DBT_DEVICEARRIVAL Then Run ("E:\run_emu.bat") EndIf EndFunc While 1 $GuiMsg = GUIGetMsg() WEnd Any help would be greatly appreciated, Cheers, Hamcher. Link to comment Share on other sites More sharing options...
Somerset Posted February 19 Share Posted February 19 DriveStatus in the help file Link to comment Share on other sites More sharing options...
mistersquirrle Posted February 19 Share Posted February 19 (edited) I think DriveGetDrive is a better option, and you can specify the type of drives: #include <Array.au3> Local $aDrives $aDrives = DriveGetDrive('all') _ArrayDisplay($aDrives) I would then use FileExists to see if your file exists before just blindly continuing, and probably see if you can use something like FileGetVersion to make sure that you're running the right file/version of whatever you want: #include <Array.au3> Local $aDrives $aDrives = DriveGetDrive('all') _ArrayDisplay($aDrives) For $iDrive = 1 To $aDrives[0] If FileExists($aDrives[$iDrive] & ':\run_emu.bat') = 1 Then ;~ If FileGetVersion($aDrives[$iDrive] & ':\run_emu.bat', 'FileVersion') = '1.0.0.0' ConsoleWrite('File is on drive: ' & $aDrives[$iDrive] & @CRLF) ExitLoop EndIf Next Edited February 19 by mistersquirrle We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
ioa747 Posted February 19 Share Posted February 19 if I assume that "E:\run_emu.bat" is on USB , else give a know path from USB in FileExists("E:\run_emu.bat") Local $iFileExists = FileExists("E:\run_emu.bat") If $iFileExists Then Run ("E:\run_emu.bat") EndIf Link to comment Share on other sites More sharing options...
Solution Hamcher Posted February 19 Author Solution Share Posted February 19 All solutions have been helpful. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now