好的,部分歸功於Fadi的評論,這讓我發現了一條稍微不同的谷歌路徑,我發現我的方式是我的方式answer。這個答案是爲了找到一個文件的UNC而設計的,所以我稍微修改了它。
這裏是我的代碼:
Public Shared Function GetDriveUNC(ByVal sDrive As String) As String
If sDrive.IndexOf(":") Then
Dim searcher As New ManagementObjectSearcher("SELECT RemoteName FROM win32_NetworkConnection WHERE LocalName = '" + sDrive.Substring(0, 2) + "'")
For Each managementObject As ManagementObject In searcher.[Get]()
Dim sRemoteName As String = TryCast(managementObject("RemoteName"), String)
Return (New Uri(sRemoteName)).ToString()
Next
Return sDrive
Else
Return sDrive
End If
End Function
也許是這樣的:[如何檢查映射網絡驅動器連接(https://stackoverflow.com/q/17848370/4039286) – Fadi
感謝一個想法,但這將返回映射驅動器的驅動器號。我正在查看是否在映射的所有驅動器中,是否有指向UNC \\ MyServer \ Share的驅動器。 –