110,528
社区成员
发帖
与我相关
我的任务
分享
ConnectionOptions options =
new ConnectionOptions();
options.Username = "administrator";
options.Password = "********";
// Make a connection to a remote computer.
// Replace the "FullComputerName" section of the
// string "\\\\FullComputerName\\root\\cimv2" with
// the full computer name or IP address of the
// remote computer.
ManagementScope scope =
new ManagementScope(
"\\\\FullComputerName\\root\\cimv2", options);
scope.Connect();
//Query system for Operating System information
ObjectQuery query = new ObjectQuery(
"select * from Win32_Processor");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine("CPU : {0}",
m["LoadPercentage"].ToString()); //cpu 使用率
}
double totalMem = 0;
string strMsg = "";
ObjectQuery query1 = new ObjectQuery(
"Select TotalPhysicalMemory from Win32_LogicalMemoryConfiguration");
ManagementObjectSearcher search = new ManagementObjectSearcher(scope, query1);
int i = 0;
ManagementObjectCollection queryCollection1 = search.Get();
foreach (ManagementObject info in queryCollection1)
{
i = i + 1;
totalMem += Convert.ToDouble(info["TotalPhysicalMemory"].ToString()) / 1024;
strMsg += string.Format("物理内存({0}):大小:{1}MB", i, Convert.ToDouble(info["TotalPhysicalMemory"].ToString()) / 1024);
}
strMsg += string.Format("总物理内存的大小:{0}MB <br/>", totalMem);
Console.WriteLine(strMsg);