我正在尝试创建一个函数来将映射的驱动器路径转换为UNC路径。我做了一些谷歌搜索,发现了several different pages。我对第一个感兴趣,但我似乎无法获得合作的代码。由于原帖是在C#中,这是我的VB.NET转换:
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
我导入了System.Management
,但VS2008说ManagementObjectSearcher
和ManagementObject
未定义。任何人都可以把我推向正确的方向吗?
答案 0 :(得分:4)
您还需要在参考文献中添加System.Management。