Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

VB.Net: Path to UNC

From Wiki

Jump to: navigation, search

Sometimes it can be handy to find the UNC for a mapped drive.

  1. Private Declare Ansi Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As System.Text.StringBuilder, ByRef cbRemoteName As Int32) As Int32
  2.        
  3. Public Shared Function PathtoUNC(ByVal Path As String) As String
  4.    Dim _UNCName As New System.Text.StringBuilder(300)
  5.    Dim _UNCPath As String
  6.    Dim _Capacity As Integer = _UNCName.Capacity
  7.    If Not Path Is Nothing Then
  8.       If Path.Length > 1 Then
  9.          If Path.Substring(0, 1).ToUpper > "E" And Path.Substring(0, 1).ToUpper <= "Z" Then
  10.             WNetGetConnection(Path.Substring(0, 2), _UNCName, _Capacity)
  11.             _UNCPath = System.IO.Path.Combine(_UNCName.ToString.TrimStart, Path.Substring(3)).ToString()
  12.             Return _UNCPath
  13.          Else
  14.             Return Path
  15.          End If
  16.       End If
  17.    End If
  18.    Return Nothing
  19. End Function

383 Rating: 1.7/5 (3 votes cast)