【发布时间】:2016-11-07 15:45:51
【问题描述】:
这是我的清单:
public static List<Tuple<string, string>> hardDiskInfo(string hostname)
{
var hardDiskInfo = new List<Tuple<string, string>>();
ManagementScope Scope;
if (!hostname.Equals("localhost", StringComparison.OrdinalIgnoreCase))
{
ConnectionOptions Conn = new ConnectionOptions();
Conn.Username = Properties.Settings.Default.uName;
Conn.Password = Properties.Settings.Default.pWord;
Conn.Authority = "ntlmdomain:" + Properties.Settings.Default.doMain;
Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", hostname), Conn);
}
else
Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", hostname), null);
Scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3 OR DriveType = 4");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject mo in queryCollection)
{
foreach (PropertyData p in mo.Properties)
{
if (p.Value != null)
{
hardDiskInfo.Add(new Tuple<string, string>(p.Name.ToString(), p.Value.ToString()));
}
}
}
return hardDiskInfo;
}
我想知道调用后如何获取 p.Name 的第二个 p.Value:
hardDiskInfo(inputText.Text);
例如Win32_LogicalDisk中定义的“FreeSpace”的值。
我有更多 Win32_ 查询,所以知道这将帮助我处理所有这些查询,我会成为一只快乐的熊猫。
谢谢。
【问题讨论】:
-
我想知道调用后p.Name的第二个p.Value怎么获取:没有第二个值?
-
好吧好吧,我的错。所以我想知道如何获取 p.Name 的 p.Value。
-
它看起来像一个 NameValue 集合,所以
p有一个Name和一个Value。意思是,Name它自己是名称的值,而 deValue包含该值。我可能不明白斗争是什么。 -
困难在于我不知道该怎么做。我可以请那一行解释如何做吗?