c# 我想用WMI 来读取远程的(同一个局域网的)机器的cpu ID,主板ID,硬盘ID等,可以实现么?

 我来答
beifang1986
2010-12-08
知道答主
回答量:44
采纳率:0%
帮助的人:29.8万
展开全部
public class CPUInfo
{
#region 属性
#region CPU名称
string strCPUName = string.Empty;
public string CPUName
{
get { return strCPUName; }
set { strCPUName = value; }
}
#endregion

#region CPU序列号
string strCPUID = string.Empty;
public string CPUID
{
get { return strCPUID; }
set { strCPUID = value; }
}
#endregion
#region CPU个数
int nCPUCount = 0;
public int CPUCount
{
get { return nCPUCount; }
set { nCPUCount = value; }
}
#endregion
#region CPU制造商
string strCPUManufacturer = string.Empty;
public string CPUManufacturer
{
get { return strCPUManufacturer; }
set { strCPUManufacturer = value; }
}
#endregion
#region 当前时钟频率
string strCPUCurrentClockSpeed = string.Empty;
public string CPUCurrentClockSpeed
{
get { return strCPUCurrentClockSpeed; }
set { strCPUCurrentClockSpeed = value; }
}
#endregion
#region 最大时钟频率
string strCPUMaxClockSpeed = string.Empty;
public string CPUMaxClockSpeed
{
get { return strCPUMaxClockSpeed; }
set { strCPUMaxClockSpeed = value; }
}
#endregion
#region 外部频率
string strCPUExtClock = string.Empty;
public string CPUExtClock
{
get { return strCPUExtClock; }
set { strCPUExtClock = value; }
}
#endregion
#region 当前电压
string strCPUCurrentVoltage = string.Empty;
public string CPUCurrentVoltage
{
get { return strCPUCurrentVoltage; }
set { strCPUCurrentVoltage = value; }
}
#endregion
#region 二级缓存
string strCPUL2CacheSize = string.Empty;
public string CPUL2CacheSize
{
get { return strCPUL2CacheSize; }
set { strCPUL2CacheSize = value; }
}
#endregion
#region 数据带宽
string strCPUDataWidth = string.Empty;
public string CPUDataWidth
{
get { return strCPUDataWidth; }
set { strCPUDataWidth = value; }
}
#endregion
#region 地址带宽
string strCPUAddressWidth = string.Empty;
public string CPUAddressWidth
{
get { return strCPUAddressWidth; }
set { strCPUAddressWidth = value; }
}
#endregion
#region 运用百分比
int iCPUUsedPercent;
public int CPUUsedPercent
{
get { return iCPUUsedPercent; }
set { iCPUUsedPercent = value; }
}
#endregion
#region CPU温度
double strCPUTemperature;
public double CPUTemperature
{
get { return strCPUTemperature; }
set { strCPUTemperature = value; }
}
#endregion
#endregion
#region 构造函数
public CPUInfo()
{
GetCPUInfo();
}
#endregion
//GetCPUInfo
#region GetCPUInfo
public void GetCPUInfo()
{
#region 运用百分比
GetCPULoadPercentage();
#endregion
CPUCount = Environment.ProcessorCount; //CPU个数
//GetCPUCurrentTemperature();
//实例化一个ManagementClass类,并将Win32_Processor作为参数传递进去,
//这样就能够查询Win32_Processor这个类里面的一些信息了。
ManagementClass mClass = new ManagementClass("Win32_Processor");
//获取Win32_Processor这个类的所有实例
ManagementObjectCollection moCollection = mClass.GetInstances();
//对Win32_Processor这个类执行 遍历
foreach (ManagementObject mObject in moCollection)
{
CPUName = mObject["Name"].ToString(); //获取CPU名称
CPUID = mObject["ProcessorId"].ToString(); //获取 CPU ID
CPUManufacturer = mObject["Manufacturer"].ToString(); //获取CPU制造商
CPUCurrentClockSpeed = mObject["CurrentClockSpeed"].ToString(); //获取当前时钟频率
CPUMaxClockSpeed = mObject["MaxClockSpeed"].ToString(); //获取最大时钟频率
CPUExtClock = mObject["ExtClock"].ToString(); //获取外部频率
CPUCurrentVoltage = mObject["CurrentVoltage"].ToString(); //获取当前电压
CPUL2CacheSize = mObject["L2CacheSize"].ToString(); //获取二级缓存
CPUDataWidth = mObject["DataWidth"].ToString(); //获取数据带宽
CPUAddressWidth = mObject["AddressWidth"].ToString(); //获取地址带宽
}
}
public void GetCPUCurrentTemperature()
{
ManagementObjectSearcher mos = new ManagementObjectSearcher(@"root\wmi", @"select * from MSAcpi_ThermalZoneTemperature");
foreach (ManagementObject mo in mos.Get())
{
CPUTemperature = Convert.ToDouble(Convert.ToDouble(mo["CurrentTemperature"].ToString()) - 2732) / 10;
}
}

public int GetCPULoadPercentage()
{
int CPUusedpercent = 0;
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
CPUusedpercent = int.Parse(queryObj["LoadPercentage"].ToString());
CPUUsedPercent = CPUusedpercent;
break;
}
}
catch
{
CPUusedpercent = 0;
}
return CPUusedpercent;
}
#endregion
}
icefeiji
2010-12-08
知道答主
回答量:10
采纳率:0%
帮助的人:4.6万
展开全部
需要知道对方系统的管理员和密码,并且支持WMI,且防火墙没有拦截此操作。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式