Q

How do I get the UNC path from a drive letter in .NET?

How do I get the UNC path from a drive letter in .NET? I tried using the DECLARE wnetgetconnection32 API call, and could not get that working either. Any suggestions?
Keep in mind that WnetGetConnection will only return the UNC path for a mapped drive, not just any drive. The program below will show the UNC name for the mapped Q: drive.
Module Module1

    Public Declare Function WNetGetConnection Lib "mpr.dll" Alias _
             "WNetGetConnectionA" (ByVal lpszLocalName As String, _
             ByVal lpszRemoteName As String, ByRef cbRemoteName As Integer) As 
Integer

    Sub Main()

        Dim ret As Integer
        Dim out As String = New String(" ", 260)
        Dim len As Integer = 260

        ret = WNetGetConnection("Q:", out, len)

        Console.WriteLine(out)
    End Sub

End Module

This was first published in March 2004

Dig deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close