A script I have that checks if an external HDD is connected, which has a prompt to mount the drive, with the option 'retry' and 'cancel'. If I click 'retry' it says it has found the drive, even though it's not connected, how can I fix this ?

show the code you're using.

const DriveLetter = "O"

dim fso
set fso = CreateObject("Scripting.FileSystemObject")

dim USBDrive
Set USBDrive = Nothing
On Error Resume Next
Do
  USBDrive = fso.Drives(CStr(DriveLetter))
  If Err.Number<>0 Then
    Err.Clear
    If MsgBox("Drive " & DriveLetter & ": is not available, Please mount the drive", vbRetryCancel, "Test") = vbCancel Then
      Set fso = Nothing
      Wscript.Quit
    End If
    Set USBDrive = Nothing
  End If
  If UsbDrive <> Nothing Then Exit Do
Loop
set fso = Nothing

MsgBox "Drive " & DriveLetter & " Found"

Try this

const DRIVE = "F"

set fso = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

Do
    set drv = fso.Drives(DRIVE) 
    if err.Number = 0 then Exit Do

    If MsgBox("Drive " & DRIVE & ": is not available, Please mount the drive", vbRetryCancel, "Test") = vbCancel Then
        Wscript.Quit
    End If

    err.Clear

Loop

MsgBox "Drive " & DRIVE & " Found"

Running the script just causes, the drive to be found even though it's not plugged in.

I tried it on my computer (Windows 7 Pro). I have an external hard drive assigned to F. I run the script and click on Retry a couple of times before plugging in the drive. Then I click on Retry until the drive is recognized. No crashes.

I'm running it on Windows8 and it's not working like that for me, the way it's working for you is exactly how I want it to work :(

Unfortunately (for you) I can't test it under Windows 8. Perhaps some else out there can?

I'm going to have to get someone else to test to find where the problem lies.

Just to clairify when you run the script, you can prompt over and over that the drive is not connected, until you connect the drive it automatically stops asking or you have to click 'retry' ?

Edit: It works :)
Can the prompt automatically disappear when the drive is connected ?

MsgBox is modal so when it is displayed the script pauses at that point. You can't make it auto-acknowledge if the drive comes online. Another option is to do something like

const DRIVE = "F"

set fso = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

Do
    set drv = fso.Drives(DRIVE) 

    if err.Number = 0 then
        wscript.echo "Drive found"
        exit do
    end if

    wscript.echo "Drive not found. Press CTRL-C to quit or wait for auto retry"
    wscript.Sleep 1000

    err.Clear

Loop

or to write a VB app which does the same thing except displays the results after each pass in a label, and provides a button (for example) to quit.

That is perfect.

or to write a VB app which does the same thing except displays the results after each pass in a label, and provides a button (for example) to quit.

I don't understand ? :)
The only extra I may want is another type of message, as it stands, it's perfect :)

Well then, enjoy :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.