我想從我的環境中的幾臺服務器獲取多個信息。WMI - 查詢多個信息
此代碼正在工作,但此代碼是獲取信息的好方法嗎?
可以在每次請求時調用「new ManagementObjectSearcher」嗎?
ManagementObjectSearcher cpuUsage = new ManagementObjectSearcher
("\\\\" + strComputer + "\\root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in cpuUsage.Get())
{
Console.WriteLine("LoadPercentage: {0}", queryObj["LoadPercentage"]);
}
ManagementObjectSearcher totalRAM = new ManagementObjectSearcher
("\\\\" + strComputer + "\\root\\CIMV2",
"SELECT * FROM Win32_ComputerSystem");
foreach (ManagementObject queryObj in totalRAM.Get())
{
Console.WriteLine("TotalPhysicalMemory: {0}", queryObj["TotalPhysicalMemory"]);
}
ManagementObjectSearcher freeRAM = new ManagementObjectSearcher
("\\\\" + strComputer + "\\root\\CIMV2",
"SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory");
foreach (ManagementObject queryObj in freeRAM.Get())
{
Console.WriteLine("AvailableMBytes: {0}", queryObj["AvailableMBytes"]);
}