Reputation: 12560
I am trying to create a function to convert a mapped drive path to a UNC path. I did some googling and found several different pages on the matter. I am most interested in the first one, but I cannot seem to get the code to cooperate. Since the original post was in C#, here is my VB.NET conversion:
Public Shared Function GetUniversalName(ByVal sFilePath As String) As String
If sFilePath = String.Empty OrElse sFilePath.IndexOf(":") Then
Return sFilePath
End If
If sFilePath.StartsWith("\") Then
Return (New Uri(sFilePath)).ToString()
End If
Dim searcher As New ManagementObjectSearcher("SELECT RemoteName FROM win32_NetworkConnection WHERE LocalName = '" + sFilePath.Substring(0, 2) + "'")
For Each managementObject As ManagementObject In searcher.[Get]()
Dim sRemoteName As String = TryCast(managementObject("RemoteName"), String)
sRemoteName += sFilePath.Substring(2)
Return (New Uri(sRemoteName)).ToString()
Next
Return sFilePath
End Function
I have imported System.Management
, but VS2008 says ManagementObjectSearcher
and ManagementObject
are not defined. Can anyone push me in the right direction?
Upvotes: 2
Views: 10083
Reputation: 35117
You need to add System.Management in your references as well.
Upvotes: 4