Jump to content

Recommended Posts

Posted

Having a hard time getting DriveStatus to be used as a numerical value. it yields Unknown, Ready, Not Ready, and Invalid. what I'm trying to do is use that output and convert that to a numerical value to be used further in the script. Basically to substrate from an array's value.


Google isn't much help, and starting to wonder if what I'm trying to do is possible.


I'm using Autoit to watch for connected USB and respond accordingly to a given value. using DriveGetDrive works phenomenally except that it doesn't account for USBs that won't mount AKA "corrupted" USBs. These unmounted USB, I'm using for testing, are being seen by DriveGetDrive, which then adds to the output. This then causes issues as it messes with actions down the line. What I'm hoping to do is to utilize DriveStatus in conjunction with DriveGetDrive. confirming these USB's are in a serviceable state and so it would respond more accurately and accordingly. potentially even representing them on the GUI to warn my Users to not proceed with using them and contacting me for assistance.

Posted

Here is an easy method using a map.

Code is a modified example from the helpfile.

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Local $mDriveStatus[]
$mDriveStatus[$DS_UNKNOWN]=1
$mDriveStatus[$DS_READY]=2
$mDriveStatus[$DS_NOTREADY]=3
$mDriveStatus[$DS_INVALID]=4

Local $aArray = DriveGetDrive($DT_ALL)
Local $sStatus
If @error Then
    ; An error occurred when retrieving the drives.
    MsgBox($MB_SYSTEMMODAL, "", "It appears an error occurred.")
Else
    For $i = 1 To $aArray[0]
        $sDriveStatus = DriveStatus($aArray[$i])
        ; Show all the drives found and convert the drive letter to uppercase.
        MsgBox($MB_SYSTEMMODAL, "", "Drive " & $i & "/" & $aArray[0] & ":" & @CRLF & StringUpper($aArray[$i]) & @CRLF & "Status: " & $sDriveStatus & @CRLF & "StatusNumber: " & $mDriveStatus[$sDriveStatus])
    Next
EndIf

 

 

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
×
×
  • Create New...