获取映射的驱动器VB.net的UNC路径

编程入门 行业动态 更新时间:2024-10-28 11:28:16
本文介绍了获取映射的驱动器VB的UNC路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我很想从映射的驱动器获取UNC路径. 我尝试使用WNetGetConnection,但它对我不起作用.它返回错误487. 有人知道如何处理此错误或以其他任何方式获取UNC路径吗?

I neet to get UNC path from mapped drive. I tried to use WNetGetConnection, but it doesn't work for me. It returns error 487. Does anybody know how to deal with this error or any other way to get the UNC path?

推荐答案

完全使用@Alex K的P/Invoke建议,我只想发布一种通过net use命令进行管道传输的方法:

Totally go with @Alex K's P/Invoke suggestion, I just wanted to post a hack method of piping through the net use command:

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

更多推荐

获取映射的驱动器VB.net的UNC路径

本文发布于:2023-11-03 11:59:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555098.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:驱动器   路径   net   VB   UNC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!