Jump to content

Wait on user to connect usb drive


trinsic
 Share

Recommended Posts

Man i suck.. I cant figure out how to do this, basicley I want to write a script that.

1. Checks to see if a drive letter exists. If so the script just exits.

2. If the drive letter does not exist I want a window to come up with an ok prompt that asks the user to connect the device associated with the drive letter.

3. If the user clicks ok I want it to check to see if the drive letter exisists once again, if not another window comes up and says that the device does not exist try again. If the user clicks ok and the device associated with the drive letter exists just exit.

4. If the user clicks the close button X, I want the script to stop.

Here is what I tried to do, but I am getting confused with if, then else statments..

#include <GUIConstantsEx.au3>
$drivestatus = DriveStatus( "f:\" )
If $drivestatus = "Ready" Then 
    Exit
ElseIf $drivestatus = "Invalid" Then
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate("Backup Drive Missing", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Please Connect the Device", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")
GUISetState(@SW_SHOW)
EndIf

While 1
  Sleep(1000) ; Idle around
WEnd

Func OKButton()
 ;Note: at this point @GUI_CTRLID would equal $okbutton,
 ;and @GUI_WINHANDLE would equal $mainwindow
    $drivestatus = DriveStatus( "f:\" )
    If $drivestatus = "Invalid" Then
    MsgBox(0, "GUI Event", "Drive not found")
    ElseIf $drivestatus = "Ready" Then
        Exit
    EndIf
EndFunc

Func CLOSEClicked()
 ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
 ;and @GUI_WINHANDLE would equal $mainwindow\
  Exit
EndFunc

Any help would be appericiated.

Link to comment
Share on other sites

It seems to work fine for me.

But if you want a simplfied version, you might consider:

While DriveStatus("f:\") = "Invalid"
    $result = MsgBox(48 + 1, "Backup Drive Missing", "Please Connect the Device")
    Switch $result
        Case 1;OK pressed
            ContinueLoop
        Case 2; Cancel pressed
            Exit
    EndSwitch
WEnd

:P

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...