C#用wmi读硬件,cpu,声卡,网卡,显卡

本文详细介绍了如何利用C#编程语言通过Windows Management Instrumentation(WMI)来读取系统的硬件信息,包括CPU、声卡、网卡和显卡等关键组件。通过示例代码展示了如何有效地查询和显示这些设备的详细数据,帮助开发者更好地进行系统监控和管理。
摘要由CSDN通过智能技术生成

 

using  System;
using  System.Drawing;
using  System.Collections;
using  System.ComponentModel;
using  System.Windows.Forms;
using  System.Data;
using  System.Management;
using  System.Text;

namespace  WindowsApplication2
{
    
/**//**//**//// <summary>
    
/// Form1 的摘要说明。
    
/// </summary>

    public class Form1 : System.Windows.Forms.Form
    
{
        
private System.Windows.Forms.ListView listView1;
        
private System.Windows.Forms.ColumnHeader name;
        
private System.Windows.Forms.ColumnHeader caption;
        
private System.Windows.Forms.ColumnHeader desc;
        
private System.Windows.Forms.MenuItem menuItem1;
        
/**//**//**//// <summary>
        
/// 必需的设计器变量。
        
/// </summary>

        private System.ComponentModel.Container components = null;

        
public Form1()
        
{
            
//
            
// Windows 窗体设计器支持所必需的
            
//
            InitializeComponent();

            
//
            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            
//
            this.getnetwork();
            
this.getvideo();
            
this.getsound();
            
this.getcpu();
            
this.getmemory();
            
this.getmainboard();
        }

        
//得到硬件的信息集合
        public ManagementObject dosth(string[] hstra)
        
{
            
string hname=hstra[0];
            ManagementObjectSearcher query 
= new ManagementObjectSearcher(hstra[1]);
            ManagementObjectCollection qc 
= query.Get();
            
foreach( ManagementObject obj in qc)
            
{
                
switch(hname)
                
{
                    
case "网卡":
                        
if((bool)obj["ipEnabled"]==false)
                            
continue;
                        
//this.getallinfo(obj);
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值