vb.net如何检查网络驱动器是否持久映射
我使用以下代码在系统上布局网络驱动器。我想添加第三列以实现持久性,但在 vb.net 中我不知道如何检查驱动器是否具有持久性映射。有什么建议吗?
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
If drive_info.DriveType().ToString = "Network" Then
With maps.Items.Add(drive_info.Name)
.SubItems.Add(drive_info.DriveType().ToString)
End With
End If
Next drive_info
I use the following code to layout network drives on a system. I want to add a third column for persistence but in vb.net I do not know how to check if a drive has a persistent map or not. Any suggestions?
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
If drive_info.DriveType().ToString = "Network" Then
With maps.Items.Add(drive_info.Name)
.SubItems.Add(drive_info.DriveType().ToString)
End With
End If
Next drive_info
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您本来可以在 WMI 中完成此操作,而无需任何(好吧,更少)令人讨厌的麻烦。
例如,
显然您需要添加对 System.Management.dll 的引用并将 Z: 更改为您正在检查的驱动器,或者您可能可以仅使用该代码片段替换所有代码,因为删除 WHERE 子句将返回所有映射的驱动器。
You could have always done it in WMI without any (well okay fewer) nasty cludges.
e.g.
Obviously you need to add a reference to System.Management.dll and change Z: to the drive you are checking, or you could probably replace all your code with just that snippet as removing the WHERE clause will return all mapped drives.
这可能对你有帮助。它是一个枚举网络资源的C#类,并且具有区分持久连接的能力:
http://www.codeproject.com/KB/cs/csenumnetworkresources.aspx?msg=964694
我很抱歉它是用 C# 编写的,但它做了一些我不知道的事情,比如整理内存VB中怎么做。
常量被传递到 EnumerateServers 函数以提供对输出的精细控制。您会发现感兴趣的常量是:
枚举记住的(持久)连接。
This might help you. It is a C# class that enumerates network resources, and has the ability to distinguish persistent connections:
http://www.codeproject.com/KB/cs/csenumnetworkresources.aspx?msg=964694
I apologize that it is in C#, but it does some things like marshaling memory that I don't know how to do in VB.
Constants are passed to the
EnumerateServers
function to provide fine control of the output. The constant you would find of interest is:Enumerates remembered (persistent) connections.