| WNetGetConnection |
| |
| |
| Option Base 1 | |
| Private Declare Function WNetGetConnection Lib "User" (ByVal LocalName As String, _ |
| ByVal RemoteName As String, RetLength As Integer) As Integer | 32 Bit version of above |
| |
| Private Declare Function WNetGetConnectionA Lib "MPR.DLL" (ByVal LocalName As String, _ |
| ByVal RemoteName As String, RetLength As Long) As Long |
| |
| Sub Netzlaufwerke() | |
| Dim strServerNames() As String, intNumServers As Integer, i As Integer |
| ReDim strServerNames(2, 23) As String | Initialise string array |
| intNumServers = pfGetConnection(strServerNames) | Execute function |
| ReDim Preserve strServerNames(2, intNumServers) | Shrink array to get rid of empty elements |
| For i = 1 To intNumServers | Display results |
| MsgBox strServerNames(1, i) & " = " & strServerNames(2, i) |
| Next | |
| End Sub | |
| |
| Function pfGetConnection(ByRef strServers() As String) As Integer |
| Dim lngMaxLen As Long, strLocalName As String, strRemoteName As String |
| Dim intCount As Integer, lngGetConRet As Long | |
| For intCount = 65 To 90 | Loop through drive letters D to Z |
| lngMaxLen = 255 | Length of fixed string pointer for API call |
| strLocalName = Chr(intCount) & ":" | Drive letter with trailing colon |
| strRemoteName = Space(lngMaxLen) | initialise string pointer |
| If Not Application.OperatingSystem Like "*32*" Then | Feed drive letter into API function |
| 16 bit version |
| lngGetConRet = WNetGetConnection (strLocalName, strRemoteName, CInt(lngMaxLen)) |
| Else | |
| 32 bit version |
| lngGetConRet = WNetGetConnectionA (strLocalName, strRemoteName, lngMaxLen) |
| End If | |
| Strip out terminating Null character and trailing spaces |
| strRemoteName = Left(strRemoteName, InStr(strRemoteName, Chr(0)) - 1) |
| If Not Len(strRemoteName) = 0 Then | |
| pfGetConnection = pfGetConnection + 1 | Load drive letter into referenced array |
| strServers(1, pfGetConnection) = strLocalName | |
| strServers(2, pfGetConnection) = strRemoteName | |
| End If | |
| Next intCount | |
| End Function | |
| |