我需要从映射驱动器获取UNC路径。 我试图使用WNetGetConnection,但它不适合我。它返回错误487. 有没有人知道如何处理这个错误或任何其他方式来获得UNC路径?获取映射驱动器的UNC路径VB.net
2
A
回答
1
您可以使用WNetGetUniversalName
API。
4
与@Alex K公司的P/Invoke建议共走了,我只是想通过net use
命令发布管道的破解方法:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim RemotePath = GetUncSourcePath("v"c)
If String.IsNullOrEmpty(RemotePath) Then
Trace.WriteLine("there was an error")
Else
Trace.WriteLine(RemotePath)
End If
Me.Close()
End Sub
Private Shared Function GetUncSourcePath(ByVal driveLetter As Char) As String
If String.IsNullOrEmpty(driveLetter) Then Throw New ArgumentNullException("driveLetter")
If (driveLetter < "a"c OrElse driveLetter > "z") AndAlso (driveLetter < "A"c OrElse driveLetter > "Z") Then Throw New ArgumentOutOfRangeException("driveLetter", "driveLetter must be a letter from A to Z")
Dim P As New Process()
With P.StartInfo
.FileName = "net"
.Arguments = String.Format("use {0}:", driveLetter)
.UseShellExecute = False
.RedirectStandardOutput = True
.CreateNoWindow = True
End With
P.Start()
Dim T = P.StandardOutput.ReadToEnd()
P.WaitForExit()
For Each Line In Split(T, vbNewLine)
If Line.StartsWith("Remote name") Then Return Line.Replace("Remote name", "").Trim()
Next
Return Nothing
End Function
0
作品比API调用像http://vbnet.mvps.org/index.html?code/network/uncfrommappeddrive.htm对我好,更简单 唯一的是我不得不添加一行代码Dim Dim变量Line。
感谢您的帮助
+0
欢迎来到SO!这个答案似乎更适合作为评论,而不是对上述问题的回答。 – Boeckm 2012-11-06 16:35:47
相关问题
- 1. 从模拟后的映射驱动器号获取UNC路径
- 2. 从本地路径或映射路径获取UNC路径
- 3. 使用C#,如何获取“Application.StartupPath”以返回映射的驱动器路径而不是UNC路径?
- 4. 将UNC源映射为驱动器
- 5. Cygwin访问Windows UNC映射驱动器
- 6. 如何在Java应用程序中获取映射网络驱动器的UNC路径
- 7. 如何从JFileChooser中检索UNC路径而不是映射的驱动器路径
- 8. 无法获取映射驱动器的关联网络UNC C/C++
- 9. 从UNC路径获取本地路径
- 10. 无法使用VB.net映射驱动器
- 11. 如何从服务器驱动器获取映像路径
- 12. 如何获取通过网络驱动器访问的文件的UNC路径?
- 13. 如何确定映射驱动器的实际路径?
- 14. 编写批处理以更改映射驱动器的路径
- 15. Powershell使用映射驱动器作为根路径
- 16. WSH映射驱动器叶默认路径集
- 17. 无法使用路径和密码映射网络驱动器
- 18. 查找网络驱动器的UNC路径?
- 19. 如何将具有驱动器号的路径转换为UNC路径
- 20. xcopy使用unc路径添加虚拟网络驱动器
- 21. 如何在vb.net中获取服务器本地驱动器路径?
- 22. 如何使用映射的驱动器路径而不是真正的路径使Powershell输出文件路径?
- 23. 映射网络驱动器
- 24. 映射Sharepoint驱动器
- 25. Delphi - 映射驱动器ipaddress
- 26. 映射网络驱动器
- 27. 映射网络驱动器
- 28. 使用动态路径获取对象的响应映射restkit
- 29. File.Copy从UNC路径(同一服务器)UNC路径查询
- 30. 将映射或UNC路径转换为http url
不为我工作...一直没有返回:( – Nitesh 2011-09-29 05:13:25
@ rbsoft.sol,下降到命令行运行'净使用v:','替换五:用'你的映射驱动器,你看到一行说'Remote name'? – 2011-09-29 13:06:37
@ Chris..No,我得到“网络连接无法找到”..我正在使用网络c: – Nitesh 2011-09-30 04:14:56