Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than mpr, prefix the name with the module name and a period.
WNetGetConnection (mpr)
.
C# Signature:
[DllImport("mpr.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int WNetGetConnection([MarshalAs(UnmanagedType.LPTStr)] string localName, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName, ref int length);
public static extern int WNetGetConnection([MarshalAs(UnmanagedType.LPTStr)] string localName, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName, ref int length);
VB Signature:
''' <summary>
''' Use to get UNC Path of a Mapped Drive
''' </summary>
''' <param name="localName"></param>
''' <param name="remoteName"></param>
''' <param name="length"></param>
''' <returns></returns>
''' <remarks></remarks>
<DllImport("mpr.dll")> _
Shared Function WNetGetConnection(<MarshalAs(UnmanagedType.LPTStr)> _
ByVal localName As String, ByVal remoteName As System.Text.StringBuilder, _
ByRef length As Integer) As Integer
End Function
Alternative VB Signature:
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal localName As String, ByVal remoteName As System.Text.StringBuilder, ByRef length As Integer) As Integer
User-Defined Types:
None.
End Function
Notes:
localName is the local name for the network resource (drive or printer)
remoteName is a string builder used to return the network name for the resource
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal localName As String, ByVal remoteName As System.Text.StringBuilder, ByRef length As Integer) As Integer
User-Defined Types:
None.
If the call fails because the StringBuilder is not large enough, the call will return a value of 234, and the Length parameter will contain the required size.
Notes:
localName is the local name for the network resource (drive or printer)
remoteName is a string builder used to return the network name for the resource
If the call fails because the StringBuilder is not large enough, the call will return a value of 234, and the Length parameter will contain the required size.
Sample Code:
// This sample code assumes you currently have a drive mapped to p:
// Find out what remote device a local mapping is to
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal localName As String, _
ByVal remoteName As System.Text.StringBuilder, ByRef length As Integer) As Integer
Sample Code for Visal Basic 2005 Express Edition:
(Without any Error-Handling)
Private Function strToUnc(ByVal path As String)
Dim length As Integer = 255
Dim UNC As New System.Text.StringBuilder(length)
WNetGetConnection(Microsoft.VisualBasic.Left(path, 2), UNC, length)
Return UNC.ToString
End Function
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal localName As String, _
ByVal remoteName As System.Text.StringBuilder, ByRef length As Integer) As Integer
'to get the UNC-Path of a network-drive use something like:
Private Sub Test()
Dim dr As String = "J:\"
MsgBox("The UNC-Path of drive " & dr & " is: " & strToUnc(dr))
End Sub
Private Function strToUnc(ByVal path As String)
Dim length As Integer = 255
Dim UNC As New System.Text.StringBuilder(length)
WNetGetConnection(Microsoft.VisualBasic.Left(path, 2), UNC, length)
Return UNC.ToString
End Function
Sample Code for VB.NET with error handling:
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" _
(ByVal localName As String, _
ByVal remoteName As System.Text.StringBuilder, _
ByRef length As Integer) As Integer
'to get the UNC-Path of a network-drive use something like:
Private Sub Test()
Dim dr As String = "J:\"
MsgBox("The UNC-Path of drive " & dr & " is: " & strToUnc(dr))
End Sub
Private Sub DisplayUncPath(ByVal aLocalPath As String)
Sample Code for VB.NET with error handling:
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" _
(ByVal localName As String, _
ByVal remoteName As System.Text.StringBuilder, _
ByRef length As Integer) As Integer
Dim theDriveName As String = aLocalPath.Substring(0, aLocalPath.IndexOf(":") + 1)
If theDriveName <> "" Then
Dim theDriveInfo As New DriveInfo(theDriveName)
If theDriveInfo.DriveType = DriveType.Network Then
Dim uncPathBuf As New StringBuilder(259)
Dim err As Integer = WNetGetConnection(theDriveName, uncPathBuf, uncPathBuf.Capacity)
If err = 0 Then
Dim pathname As String = uncPathBuf.ToString()
MessageBox.Show(aLocalPath.Replace(theDriveName, pathname))
Else
MessageBox.Show("Failed with error :" & err)
End If
Else
MessageBox.Show(theDriveName & " is not a network mapped path.")
End If
End If
End Sub
Private Sub DisplayUncPath(ByVal aLocalPath As String)
Dim theDriveName As String = aLocalPath.Substring(0, aLocalPath.IndexOf(":") + 1)
If theDriveName <> "" Then
Dim theDriveInfo As New DriveInfo(theDriveName)
If theDriveInfo.DriveType = DriveType.Network Then
Dim uncPathBuf As New StringBuilder(259)
Dim err As Integer = WNetGetConnection(theDriveName, uncPathBuf, uncPathBuf.Capacity)
If err = 0 Then
Dim pathname As String = uncPathBuf.ToString()
MessageBox.Show(aLocalPath.Replace(theDriveName, pathname))
Else
MessageBox.Show("Failed with error :" & err)
End If
Else
MessageBox.Show(theDriveName & " is not a network mapped path.")
End If
End If
End Sub
Alternative Managed API:
Do you know one? Please contribute it!
Alternative Managed API:
Do you know one? Please contribute it!
Click to read this page
10/2/2011 2:35:57 AM - txzhgh-89.110.151.174
Click to read this page
10/2/2011 2:35:57 AM - txzhgh-89.110.151.174
You can use this to get the UNC-Path (Format: "\\Computer\Path\To\Somewhere\") of a Network drive
12/16/2010 2:44:35 PM - -71.41.104.4
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByRef is a VB keyword that specifies a variable to be passed as a parameter BY REFERENCE. In other words, the pointer to the variable is passed and any change to its value made within the function or sub will change its value outside the function/sub.
4/25/2007 3:19:29 AM - anonymous
Click to read this page
10/2/2011 2:35:57 AM - txzhgh-89.110.151.174
Click to read this page
10/2/2011 2:35:57 AM - txzhgh-89.110.151.174
Click to read this page
10/2/2011 2:35:57 AM - txzhgh-89.110.151.174
Click to read this page
10/2/2011 2:35:57 AM - txzhgh-89.110.151.174
Click to read this page
10/2/2011 2:35:57 AM - txzhgh-89.110.151.174
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).