0
這裏搜索是我的清單:如何在列表的第一項
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。 – Nash
它看起來像一個NameValue集合,所以'p'有一個'Name'和一個'Value'。意思是,'Name'它自身就是名稱的值,de'Value'包含這個值。我可能不明白這些鬥爭是什麼。 –