Jump to content

Detecting USB Removal


 Share

Recommended Posts

Assuming the USB is already inserted when the script runs, I'd use this:

#include <MsgBoxConstants.au3>

Local $aArray = DriveGetDrive("ALL")
Local $ourDrive = ""

If @error Then
    MsgBox($MB_SYSTEMMODAL, "", "It appears an error occurred while enumerating the drives, exiting...")
Else
    For $i = $aArray[0] To 1 Step -1
        If DriveGetLabel($aArray[$i]) = "win7_usb" Then
            $ourDrive = $aArray[$i]
            ExitLoop
        EndIf
    Next
EndIf

If Not $ourDrive Then
    MsgBox($MB_SYSTEMMODAL, "", "Our drive was not found, exiting...")
    Exit
EndIf

While True
    Sleep(2000)
    if DriveStatus($ourDrive) <> "READY" Then
        MsgBox($MB_SYSTEMMODAL, "", "Our drive was REMOVED !!!")
        Exit
    EndIf
WEnd
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
 Share

  • Recently Browsing   0 members

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