LostOne
asked on
WNetGetConnection??
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
could someone please give me an example of how to get this to work.
could someone please give me an example of how to get this to work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My fault, I misread it. Create a new project and add a single command button to Form1. Paste code below into the From1 general declarations section. Run the project, click the button and watch the immediate window for the result.
Note: Replace "K" in the Command1_Click event with the local drive for which you wish to retrieve the associated network resource name.
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
Const ERROR_MORE_DATA = 234
Const NO_ERROR = 0
Private Sub Command1_Click()
Debug.Print GetResource("K:")
End Sub
Function GetResource(strDrv$) As String
Dim strRes$, ResLen&, RC&
ResLen = 32 'Buffersize - will be enlarged if necessary.
Do
strRes = Space(ResLen)
RC = WNetGetConnection(strDrv & Chr$(0), strRes, ResLen)
Loop Until RC <> ERROR_MORE_DATA
If RC = NO_ERROR Then
GetResource = Left(strRes, ResLen)
Else
MsgBox "Connection Error: " & RC
End If
End Function
Note: Replace "K" in the Command1_Click event with the local drive for which you wish to retrieve the associated network resource name.
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
Const ERROR_MORE_DATA = 234
Const NO_ERROR = 0
Private Sub Command1_Click()
Debug.Print GetResource("K:")
End Sub
Function GetResource(strDrv$) As String
Dim strRes$, ResLen&, RC&
ResLen = 32 'Buffersize - will be enlarged if necessary.
Do
strRes = Space(ResLen)
RC = WNetGetConnection(strDrv & Chr$(0), strRes, ResLen)
Loop Until RC <> ERROR_MORE_DATA
If RC = NO_ERROR Then
GetResource = Left(strRes, ResLen)
Else
MsgBox "Connection Error: " & RC
End If
End Function
ASKER