网站首页 新闻首页 网页设计图形动画软件编程网站开发办公软件操作系统数据库网络技术认证考试范文资料黑客攻防 书籍教程 进入论坛

C# 中利用WMI服务查询显卡信息

http://www.diybl.com/ 2007-12-26  网络 点击:  [ 评论 ]
文章搜索:    【点击打包该文章】

什么是WMI?

 WMI就是Windows Management Instrumentation(Windows管理规范)。它是Windows中的一个核心管理技术。

.NET中怎样使用WMI?

在.NET中,System.Management命名空间提供对系统管理信息和管理事件集合的访问,这些信息和事件是与Windows管理规范(WMI)结构对系统,设备和应用程序设置检测点有关的.一般情况下,应用程序和服务可以使用该命名空间下的ManagementObjectSearcher,ManagementScope,ManagementObject,ObjectQuery等类查询兴趣的管理信息(例如:在磁盘上还有多少剩余可用空间,当前CPU利用率,显示设备信息等)WMI使用类似与SQL语句,甚至可以使用Where子句,更多WMI信息请参见:

http://www.microsoft.com/china/technet/community/scriptcenter/resources/wmifaq.mspx

下面将在C#用WMI查询显示卡信息:

1.新建一个Win应用程序

2.添加System.Management.dll引用,并引入该名称空间

2.添加一个Button和ListView,并设置相应属性

 



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

using System.Management;

namespace WMI信息
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void getInfomation_Click(object sender, EventArgs e)//getInfomation为Button
        {
            
try
            
{
                ManagementObjectSearcher searcher 
= new ManagementObjectSearcher("root\CIMV2""SELECT * FROM Win32_VideoController");
                
foreach (ManagementObject info in searcher.Get())
                
{
                    
string[] item1 = "AdapterCompatibility", info["AdapterCompatibility"].ToString() };
                    listView1.Items.Add(
new ListViewItem(item1));

                    
string[] item2 = "AdapterDACType", info["AdapterDACType"].ToString() };
                    listView1.Items.Add(
new ListViewItem(item2));

                    
string[] item3 = "VideoModeDescription", info["VideoModeDescription"].ToString() };
                    listView1.Items.Add(
new ListViewItem(item3));

                    
string[] item4 = "Caption", info["Caption"].ToString() };
                    listView1.Items.Add(
new ListViewItem(item4));

                    
string[] item5 = "CurrentBitsPerPixel", info["CurrentBitsPerPixel"].ToString() };
                    listView1.Items.Add(
new ListViewItem(item5));

                    
string[] item6 ="CurrentHorizontalResolution", info["CurrentHorizontalResolution"].ToString() };
                    listView1.Items.Add(
new ListViewItem(item6));

                    
string[] item7 = "VideoProcessor", info["VideoProcessor"].ToString() };
                    listView1.Items.Add(
new ListViewItem(item7));
                    
//还有很多属性,在此不一一例举,如:Status,PNPDeviceID,Name,Monochrome,MinRefreshRate,MaxRefreshRate,InstalledDisplayDrivers
                    
//InfSection,InfFilename,DriverVersion,DeviceSpecificPens,DeviceID,Description
                }

            }

            
catch
            
{
                
//肯定会出现异常,但为了演示不处理异常!
            }

        }

    }

}

 

利用WMI还可以查询:

声音设备信息:(SELECT  * FROM Win32_SoundDevice)

驱动设备信息:(SELECT * FROM Win32_SystemDriver)

串口信息:(SELECT * FROM Win32_Serialport)

处理器信息:(SELECT * FROM Win32_Processor)

等等



如果图片或页面不能正常显示请点击这里 站内搜索:   

文章评论

请您留言

 

最新新闻