Jump to content

Recommended Posts

Posted

I am using:

If DriveStatus("S:\") <> "UNKNOWN" Then
  Return $TRUE

But I'm not sure it's working all the time.

This goes over wireless network. If doggone S: drive is accessible, I want to return TRUE. DriveStatus help file says result list may be incomplete?

This will be a bear for me to troubleshoot live. Do I just put a file on S: drive and say FileExists("S:\DontDelete.txt") or some such?

What is best practice?

J

PS: If DriveStatus("S:\") <> "INVALID" did not work.

If I am too verbose, just say so. You don't need to run on and on.

Posted

This will be a bear for me to troubleshoot live.  Do I just put a file on S: drive and say FileExists("S:\DontDelete.txt") or some such?

That sounds like a good idea, also, make the file Attrib filename.txt +RASH so it's harder to get "accidentally" deleted.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Posted

You might try DriveSpaceFree("S:")

I dunno, my network drives are always there, so I've never had to check

Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Posted (edited)

So I mapped a network drive to my laptop and ran this code, when I was inrange of my AP It returned 1. When I took it out of range it returned 0, after about 5-10 seconds. *Once windows told me it couldnt find any networks, it returned 0 immediately.

MsgBox(0,"",MappedDriveOnline("V:"))

Func MappedDriveOnline($drive)
    if DriveSpaceFree($drive) = 1 Then Return 0
    Return 1
EndFunc
Edited by Ejoc
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Posted

None of those ideas seemed complicated enough :) (actually I didn't get them in time) so I am using:

#include <Array.au3>
    $SFound = $FALSE
    $AllDrives = DriveGetDrive( "all")
    _ArraySort($AllDrives)
    If Not @error Then
        For $i = 1 To $AllDrives[0]
            $AllDrives[$i] = StringUpper($AllDrives[$i])
        Next
        If _ArrayBinarySearch($AllDrives, "S:", 1) = "" Then
            $SFound = $FALSE
        Else
            $SFound = $TRUE
            Return $TRUE
        EndIf
    EndIf

Which appears to be working so far.

(must include Arrays.au3)

Time permitting, I will test everyone's implementations. Thanks!

J

If I am too verbose, just say so. You don't need to run on and on.

Posted

You version didn't work right for me. The first few times it returned $FALSE, then it started returning $TRUE. Plus it did not check if a drive was online atm, just if it had been mapped. So when I map the drive, and then loose connection it gives me a false positive.

Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Posted (edited)

In that case, I will try all of them darn it, and pick the best!

Thanks for the heads-up, Ejoc.

Edit:

Here is the results of the test. All methods work except jdickens:

(Please bear in mind this test prog was tossed together quickly)

Note: This will kick you off your network temporarily.

;IsDriveAvailDemo01
#include <Array.au3>
#include <GUIConstants.au3>

Dim $FALSE = 0
Dim $TRUE = 1
Dim $NICConnected
Dim $MappingInQ = "\\Tcsrv\S"

Func SOff()
    RunWait("ipconfig /release", "c:/", @SW_HIDE)
    ProcessWaitClose("ipconfig.exe")
    Return $FALSE
EndFunc  ;==>SOff

Func SOn()
    RunWait("ipconfig /renew", "c:/", @SW_HIDE)
    ProcessWaitClose("ipconfig.exe")
    Return $TRUE
EndFunc  ;==>SOn

;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

Func O2clams()
    Return FileExists($MappingInQ)
EndFunc  ;==>O2clams
;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

Func jdickens()
    $SFound = $FALSE;jdickens
    $AllDrives = DriveGetDrive( "all")
    _ArraySort($AllDrives)
    If Not @error Then
        For $i = 1 To $AllDrives[0]
            $AllDrives[$i] = StringUpper($AllDrives[$i])
        Next
        $IndexOfSFound = _ArrayBinarySearch($AllDrives, "S:", 1)
        If $IndexOfSFound = "" And (@error = 0) Then
            $SFound = $FALSE
          ;MsgBox(0,"","Not Found" & $IndexOfSFound & " " & @error)
        Else
            If $IndexOfSFound > 0 And (@error = 0) Then
                $SFound = $TRUE
              ;MsgBox(0,"","Found" & $IndexOfSFound & " " & @error)
            EndIf
        EndIf
        Return $SFound
    EndIf
EndFunc  ;==>jdickens
;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

;Note: I doubt this will work on read-only drive, such as mapped CD:
Func MappedDriveOnline($drive);Ejoc
;    MsgBox(0, "", DriveSpaceFree($drive))
    DriveSpaceFree($drive)
    If (@error = 1) And DriveSpaceFree($drive) = 1 Then
        Return $FALSE
    Else
        IF (@error <> 1) And DriveSpaceFree($drive) > 0 Then
            Return $TRUE
        EndIf
    EndIf
EndFunc  ;==>MappedDriveOnline
;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

Func CyberSlugOn()
    Return (DriveMapGet("S:") = $MappingInQ)
EndFunc  ;==>CyberSlugOn
;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

Func CyberSlugOff()
    Return (DriveMapGet("S:") = "") And (@error = 1)
EndFunc  ;==>CyberSlugOff
;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

Func BlueDrache()
    Return FileExists("S:\DontDelete.txt")
EndFunc  ;==>BlueDrache
;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

$O2clamsSOff = 0
$jdickensSOff = 0
$MappedDriveOnlineSOff = 0
$CyberSlugSOff = 0
$BlueDracheSOff = 0

$O2clamsSOn = 0
$jdickensSOn = 0
$MappedDriveOnlineSOn = 0
$CyberSlugSOn = 0
$BlueDracheSOn = 0

$NumOTries = 1
GUICreate("IsDriveAvail Results")
$mylist = GUICtrlCreateList("", 20, 20, 340, 200)
GUISetState()

For $Tries = 1 To $NumOTries
    $NICConnected = SOff()
    If $NICConnected = O2clams() Then
        $O2clamsSOff = $O2clamsSOff + 1
    EndIf
    
    If $NICConnected = jdickens() Then
        $jdickensSOff = $jdickensSOff + 1
    EndIf
    
    If $NICConnected = MappedDriveOnline("S:\") Then
        $MappedDriveOnlineSOff = $MappedDriveOnlineSOff + 1
    EndIf
    
    If $NICConnected = CyberSlugOff() Then
        $CyberSlugSOff = $CyberSlugSOff + 1
    EndIf
    
    If $NICConnected = BlueDrache() Then
        $BlueDracheSOff = $BlueDracheSOff + 1
    EndIf
    
    
    $NICConnected = SOn()
    If $NICConnected = O2clams() Then $O2clamsSOn = $O2clamsSOn + 1
    
    
    If $NICConnected = jdickens() Then $jdickensSOn = $jdickensSOn + 1
    
    
    If $NICConnected = MappedDriveOnline("S:\") Then $MappedDriveOnlineSOn = $MappedDriveOnlineSOn + 1
    
    
    If $NICConnected = CyberSlugOn() Then $CyberSlugSOn = $CyberSlugSOn + 1
    
    
    If $NICConnected = BlueDrache() Then $BlueDracheSOn = $BlueDracheSOn + 1
    
    GUICtrlSetData($mylist, "")
    GUICtrlSetData($mylist, "$O2clamsSOff, " & $O2clamsSOff & "|")
    GUICtrlSetData($mylist, "$jdickensSOff, " & $jdickensSOff & "|")
    GUICtrlSetData($mylist, "$MappedDriveOnlineSOff, " & $MappedDriveOnlineSOff & "|")
    GUICtrlSetData($mylist, "$CyberSlugSOff, " & $CyberSlugSOff & "|")
    GUICtrlSetData($mylist, "$BlueDracheSOff, " & $BlueDracheSOff & "|")
    
    GUICtrlSetData($mylist, "$O2clamsSOn, " & $O2clamsSOn & "|")
    GUICtrlSetData($mylist, "$jdickensSOn, " & $jdickensSOn & "|")
    GUICtrlSetData($mylist, "$MappedDriveOnlineSOn, " & $MappedDriveOnlineSOn & "|")
    GUICtrlSetData($mylist, "$CyberSlugSOn, " & $CyberSlugSOn & "|")
    GUICtrlSetData($mylist, "$BlueDracheSOn, " & $BlueDracheSOn & "|")
    GUISetState()
    
Next
GUICtrlSetData($mylist, "")
GUICtrlSetData($mylist, "$O2clamsSOff, " & $O2clamsSOff & "|")
GUICtrlSetData($mylist, "$jdickensSOff, " & $jdickensSOff & "|")
GUICtrlSetData($mylist, "$MappedDriveOnlineSOff, " & $MappedDriveOnlineSOff & "|")
GUICtrlSetData($mylist, "$CyberSlugSOff, " & $CyberSlugSOff & "|")
GUICtrlSetData($mylist, "$BlueDracheSOff, " & $BlueDracheSOff & "|")

GUICtrlSetData($mylist, "$O2clamsSOn, " & $O2clamsSOn & "|")
GUICtrlSetData($mylist, "$jdickensSOn, " & $jdickensSOn & "|")
GUICtrlSetData($mylist, "$MappedDriveOnlineSOn, " & $MappedDriveOnlineSOn & "|")
GUICtrlSetData($mylist, "$CyberSlugSOn, " & $CyberSlugSOn & "|")
GUICtrlSetData($mylist, "$BlueDracheSOn, " & $BlueDracheSOn & "|")
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Sleep(100)
    
WEnd
Exit

J

IsDriveAvailDemo01.au3

Edited by jdickens

If I am too verbose, just say so. You don't need to run on and on.

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