取出主板信息,其中Form1里面的testbox1文本存放结果,以下是类信息(声明,此类取内存,硬盘,等信息正常,因此复制取主板值的代码)
private ManagementClass mc;
private ManagementObjectCollection moc;
public GetSystemInfo()
{ }
public string GetBaseBoardInfo()
{
mc = new ManagementClass("Win32_BaseBoard");
moc = mc.GetInstances();
string BaseBoardInfo = string.Empty;
foreach(ManagementObject mo in moc)
{
BaseBoardInfo = "主板模式:" + mo.Properties["Name"].Value.ToString()+"\n"+
"主板型号:" + mo.Properties["Manufacturer"].Value.ToString()+"\n"+
"主板名称:" + mo.Properties["Name"].Value.ToString()+"\n"+
"主板型号:" + mo.Properties["SerialNumber"].Value.ToString();
}
moc = null;
mc = null;
return BaseBoardInfo;
}
再提问一个问题,如果有双硬盘,应该怎么取。现在只能取到一个。
C# WMI取硬件信息,求大神解释!
答案:2 悬赏:30 手机版
解决时间 2021-03-15 18:41
- 提问者网友:皆是孤独
- 2021-03-14 18:45
最佳答案
- 五星知识达人网友:轮獄道
- 2021-03-14 20:14
你那个foreach中结果保存的有问题,你实际上只取到了最后的信息,应该类似于这样
public List GetBaseBoardInfo()
{
mc = new ManagementClass("Win32_BaseBoard");
moc = mc.GetInstances();
List BaseBoardInfo =new List();
foreach(ManagementObject mo in moc)
{
BaseBoardInfo.Add("主板模式:" + mo.Properties["Name"].Value.ToString()+"\n"+
"主板型号:" + mo.Properties["Manufacturer"].Value.ToString()+"\n"+
"主板名称:" + mo.Properties["Name"].Value.ToString()+"\n"+
"主板型号:" + mo.Properties["SerialNumber"].Value.ToString());
}
moc = null;
mc = null;
return BaseBoardInfo;
}然后在Form1中比如放一个richtextbox控件
List list=GetBaseBoardInfo();
foreach(string str in list)
richTextBox1.AppendText(str+"\r\n\r\n");
public List
{
mc = new ManagementClass("Win32_BaseBoard");
moc = mc.GetInstances();
List
foreach(ManagementObject mo in moc)
{
BaseBoardInfo.Add("主板模式:" + mo.Properties["Name"].Value.ToString()+"\n"+
"主板型号:" + mo.Properties["Manufacturer"].Value.ToString()+"\n"+
"主板名称:" + mo.Properties["Name"].Value.ToString()+"\n"+
"主板型号:" + mo.Properties["SerialNumber"].Value.ToString());
}
moc = null;
mc = null;
return BaseBoardInfo;
}然后在Form1中比如放一个richtextbox控件
List
foreach(string str in list)
richTextBox1.AppendText(str+"\r\n\r\n");
全部回答
- 1楼网友:野慌
- 2021-03-14 20:43
foreach (propertydata pc in mymac.properties)
{
//some codes ...
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯