c# - 使用 WMI 列出映射的网络驱动器
问题描述
我有一个用 c# 编写的应用程序,它创建了所有映射的网络驱动器的列表。
我使用 WMI 来实现这一点,我是这样做的:
List < NetworkConnection > networkConnections = new List < NetworkConnection > ();
try {
var path = new ManagementPath();
path.NamespacePath = "\\ROOT\\CIMV2";
path.ClassName = "Win32_NetworkConnection"; //https://msdn.microsoft.com/en-us/library/aa394220(v=vs.85).aspx
var management = new ManagementClass(path);
foreach(ManagementObject obj in management.GetInstances()) {
NetworkConnection networkConnection = new NetworkConnection() {
LocalName = (string) obj.Properties["LocalName"].Value,
Name = (string) obj.Properties["Name"].Value,
RemotePath = (string) obj.Properties["RemotePath"].Value,
UserName = (string) obj.Properties["UserName"].Value,
IsPersistent = (bool) obj.Properties["Persistent"].Value,
ConnectionState = (string) obj.Properties["ConnectionState"].Value
};
networkConnections.Add(networkConnection);
}
} catch (Exception ex) {
log.Error($ "Failed to get network connections.", ex);
}
return networkConnections;
虽然这确实适用于我的测试客户端 W7 和 W8 64 位和 32 位。它不适用于我的 W10 客户端。在 W10 上,我只得到一个空列表。
看起来 management.GetInstances() 没有返回任何内容。但为什么?
任何帮助是极大的赞赏!谢谢!
解决方案
推荐阅读
- php - 如何使用functions.php向网站管理员发送评论通知消息并发布作者?
- php - 如何分离codeigniter v3.1.10中特定的config.php、database.php、constant.php文件域?
- spring - 控制同一用户的多个会话
- c - 在没有大括号的单语句块之前制作clang格式的换行符
- php - 在 laravel 如何在单个视图中显示来自两个不同模型的值
- python - 尝试通过 python 刷新和保存 .xlsm 文件时获取文件存在覆盖警报,即使 DisplayAlerts 设置为 False
- image - 使用 ImageResizer 并在表示许可证问题的图像上获取红色像素
- reactjs - 在下载 blob 文件之前显示加载消息
- excel - xmlhttp中的操作超时。在VBA中发送
- codeigniter - 在加载纯 html 标签的 codeigniter 中查看