Jump to content

Recommended Posts

Posted

Hope someone can point me in the right direction on this. I am using the drive mapping functions in AutoIt to connect to a network drive. I used DriveMapAdd ("*"...) to choose the next available drive letter. Here is the problem. This mapped to a drive letter that was in use but the server was unavailable. I tried using the DriveStatus function but the "INVALID" return value does not help. There is a big difference between a drive letter not existing and the mapped drive being unavailable. I checked each of the related functions but each shows that the drive would be available. Does anyone have any suggestions to help with this?

Posted (edited)

You could try Ping()ing the server first to get a better handle on the network status.

Edit: Also, you are checking @error of DriveMapAdd() already right?

Edited by evilertoaster
Posted

You could try Ping()ing the server first to get a better handle on the network status.

Edit: Also, you are checking @error of DriveMapAdd() already right?

Thanks for reply.

The DriveMapAdd function mapped the drive correctly but to a drive letter that was being used. It ignored the fact that a drive letter was mapped but in a disconnected state so there is no error condition according to the function. I wanted to use the DriveStatus function to check the status of a drive letter before mapping but it also ignores drives in a disconnected state. The "invalid" return value from that function means that the drive letter does not exist or a network share is unavailable. I have found no AutoIt function to get the information from a mapped drive when in the disconnected state. This includes getting the server information so pinging would also not be an option.

Again, thanks for taking the time to replay. I appreciate it.

Posted (edited)

Thanks for reply.

The DriveMapAdd function mapped the drive correctly but to a drive letter that was being used. It ignored the fact that a drive letter was mapped but in a disconnected state so there is no error condition according to the function. I wanted to use the DriveStatus function to check the status of a drive letter before mapping but it also ignores drives in a disconnected state. The "invalid" return value from that function means that the drive letter does not exist or a network share is unavailable. I have found no AutoIt function to get the information from a mapped drive when in the disconnected state. This includes getting the server information so pinging would also not be an option.

Again, thanks for taking the time to replay. I appreciate it.

Hi,

this gives local drive letter and connection state.

#include <array.au3> ; only needed to display array
Global $ardriveletter [1] [2]
_getdriveletter ()
; code what you want in the for loop to detect used letters for not connecting
;For $i = 0 To UBound ($ardriveletter) - 1
    ;MsgBox (0, "Used Drive Letters", $ardriveletter [$i]
;Next

_ArrayDisplay ($ardriveletter)

Func _getdriveletter ()
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"
    $x = 0
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkConnection", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
        For $objItem In $colItems
            $ardriveletter [$x] [0] = $objItem.LocalName
            $ardriveletter [$x] [1] = $objItem.ConnectionState
            ReDim $ardriveletter [$x + 1] [2]
        Next
    EndIf
EndFunc

;-))

Stefan

P.S: I may misunderstood. Maybe this could be a solution:

if FileExists ("\\server\share") Then
    MsgBox (0,"", "Exist")
EndIf
Edited by 99ojo

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
  • Recently Browsing   0 members

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