Jump to content

Detect when drive letter is mounted


Go to solution Solved by Hamcher,

Recommended Posts

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"
GUIRegisterMsg($WM_DEVICECHANGE , "MyFunc")
Func MyFunc($hWndGUI, $MsgID, $WParam, $LParam)
Run ("E:\run_emu.bat")
While 1
$GuiMsg = GUIGetMsg()

Any help would be greatly appreciated,

Cheers, Hamcher.

Link to comment
Share on other sites

I think DriveGetDrive is a better option, and you can specify the type of drives:

#include <Array.au3>
Local $aDrives

$aDrives = DriveGetDrive('all')

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')

For $iDrive = 1 To $aDrives[0]
    If FileExists($aDrives[$iDrive] & ':\run_emu.bat') = 1 Then
;~      If FileGetVersion($aDrives[$iDrive] & ':\run_emu.bat', 'FileVersion') = ''
        ConsoleWrite('File is on drive: ' & $aDrives[$iDrive] & @CRLF)


Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...