One workaround way to find out a network drive’s remote network name in VB, that’s because I have such a little time to find the proper way for the test case…

VB找到网络硬盘的网络名称的一种另类方法,因为我没有时间去为一个测试程序找正确的方法:

System.IO.File.Delete("c:\a.txt")

Dim cmdParam As String = String.Format(" /c net.exe use {0}: > c:\a.txt", curDriveLetter)

 

Dim pr As System.Diagnostics.Process = System.Diagnostics.Process.Start("cmd.exe", cmdParam)

While Not pr.HasExited

   System.Threading.Thread.Sleep(200)

End While

 

Dim remoteName As String = ""

If (System.IO.File.Exists("c:\a:txt")) Then

   Dim allStr As String = System.IO.File.ReadAllText("c:\a.txt")

   System.IO.File.Delete("c:\a.txt")

 

   Dim r As New Text.RegularExpressions.Regex("(?<name>\\\\.*?)\s")

   Dim m As Text.RegularExpressions.Match = r.Match(allStr)

   remoteName = m.Groups("name").Value

End If