C#中用WMI实现对驱动的查询

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WMI_驱动
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){listView1.Items.Clear();//SelectQuery selectQuery = new SelectQuery("select * from win32_logicaldisk");//硬盘盘符SelectQuery selectQuery = new SelectQuery("select * from Win32_DiskDrive");//硬盘序列号
           ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), Driver["Description"].ToString() }, -1);listView1.Items.Add(lvi);}}private void button2_Click(object sender, EventArgs e){listView1.Items.Clear();SelectQuery selectQuery = new SelectQuery("select * from Win32_SystemDriver");//驱动程序ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), Driver["Description"].ToString() }, -1);listView1.Items.Add(lvi);}}private void button3_Click(object sender, EventArgs e){listView1.Items.Clear();SelectQuery selectQuery = new SelectQuery("select * from Win32_USBController");//USB控制器ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), Driver["Description"].ToString() }, -1);//ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(),"" },-1);
                listView1.Items.Add(lvi);}SelectQuery selectQuery2 = new SelectQuery("select * from Win32_USBHub");//USB集线器ManagementObjectSearcher search2 = new ManagementObjectSearcher(selectQuery2);foreach (ManagementObject Driver in search2.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), Driver["Description"].ToString() }, -1);//ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(),"" },-1);
                listView1.Items.Add(lvi);}}private void Form1_Load(object sender, EventArgs e){listView1.Columns.Clear();//清空列记录ColumnHeader cZh = new ColumnHeader();//创建一个列cZh.Text = "名称";//列名cZh.Width = 300;ColumnHeader cCh = new ColumnHeader();cCh.Text = "描述";cCh.Width = 600;listView1.Columns.AddRange(new ColumnHeader[] { cZh, cCh });//将这两列加入listView1listView1.View = View.Details;//列的显示模式
        }private void button4_Click(object sender, EventArgs e){listView1.Items.Clear();SelectQuery selectQuery = new SelectQuery("select * from Win32_Printer ");//打印机ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(),"" }, -1);listView1.Items.Add(lvi);}}private void button5_Click(object sender, EventArgs e){listView1.Items.Clear();SelectQuery selectQuery = new SelectQuery("select * from Win32_PrinterConfiguration ");//打印机设置ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), "" }, -1);listView1.Items.Add(lvi);}}private void button6_Click(object sender, EventArgs e){listView1.Items.Clear();SelectQuery selectQuery = new SelectQuery("select * from Win32_PrintJob ");//打印机任务ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), "" }, -1);listView1.Items.Add(lvi);}}private void button7_Click(object sender, EventArgs e){listView1.Items.Clear();SelectQuery selectQuery = new SelectQuery("select * from Win32_TCPIPPrinterPort ");//打印机端口ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), "" }, -1);listView1.Items.Add(lvi);}}private void button8_Click(object sender, EventArgs e){listView1.Items.Clear();SelectQuery selectQuery = new SelectQuery("select * from Win32_PointingDevice ");//点输入设备,鼠标ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), Driver["Description"].ToString() }, -1);listView1.Items.Add(lvi);}}private void button9_Click(object sender, EventArgs e){listView1.Items.Clear();SelectQuery selectQuery = new SelectQuery("select * from Win32_Keyboard");//键盘ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), Driver["Description"].ToString() }, -1);listView1.Items.Add(lvi);}}private void button10_Click(object sender, EventArgs e){listView1.Items.Clear();SelectQuery selectQuery = new SelectQuery("select * from Win32_Printer ");//打印机ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);foreach (ManagementObject Driver in search.Get()){ListViewItem lvi = new ListViewItem(new string[] { Driver["Name"].ToString(), "" }, -1);listView1.Items.Add(lvi);}}
  }
}

仅仅实现了查询的功能,后续有待加入与设备管理器类似的管理功能!

转载于:https://www.cnblogs.com/lossingdawn/p/4123509.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/459863.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

01C语言的概述

一、计算机常识在学习C语言之前,先要了解一些计算机常识1.计算机只能识别0和1大家都知道,计算机要通电才能工作,说白了,它跟电视、洗衣机一样,都是电器。电器都有个共同的能力:懂得判断通电还是断电&#x…

mysql5.7物理备份_Mysql5.7—运维常用备份方式

一、 Mysqldump备份结合binlog日志恢复使用mysqldump进行全库备份,并使用binlog日志备份,还原时,可以使用binlog日志恢复到备份前的任意位置或时间1. Binlog简介主要用于主从复制和恢复数据库,使用mysqlbinlog命令查看binlog二进制…

XAMPP on Mac 组态 Virual Host

首先,在hosts文件中添加virtual host域名。方向127.0.0.1 我一般使用的命名约定dev-domainname.comsudo nano /private/etc/hosts # VirtualHosts Mapping 127.0.0.1 dev-domainname.com接下来配置Apache。打开Apache的配置文件 /Applications/XAMPP/etc/httpd.conf…

二叉查找树之二

BST树的经典问题 首先构造如下一棵二元查找树(BST树): C代码实现: typedef struct _BSTreeNode {int value;struct _BSTreeNode *left;struct _BSTreeNode *right;} BSTreeNode;static BSTreeNode* insert(BSTreeNode* q, int x) …

mysql 停止服务内存_服务器莫名的内存高占用 导致 MySQL 停止运行问题

这问题是年后开始出现的,服务器内存占用越来越高,一度达到90%,最后 MySQL 都停止运行了。贴吧签到的数据库用户 ID 这一项也丢失了,导致无法签到,断签了好些天,被提醒才发现,要挨打的。幸好设置…

LeetCode - Convert Sorted Array to Binary Search Tree

给出一个已排序的数组,将其转化为二叉查找树(BST)。 思路:取数组中间元素为根结点的value,则数组左侧、右侧分别为BST的左子树、右子树。递归可求解。代码如下: 1 /**2 * Definition for binary tree3 * …

匿名包装器(function(){})()

转载自***:https://bonsaiden.github.io/JavaScript-Garden/zh/#function.scopes只有一个全局作用域导致的常见错误是命名冲突。在 JavaScript中,这可以通过 匿名包装器 轻松解决。(function() {// 函数创建一个命名空间window.foo function() {// 对外…

PS滤镜绘制漂亮线条制作

先看最后效果   1.新建一图层---选择画笔画条垂直线(颜色为白色)。  2.滤镜里面的动感模糊(大小视效果而定吧)  3.两头细的线条出来了  执行后效果如…

ffmpeg.exe 笔记

2019独角兽企业重金招聘Python工程师标准>>> open_input_file: avformat_open_input 打开了输入文件 av_dict_get 获取信息 setup_find_stream_info_opts avformat_find_stream_info codec avcodec_find_decoder open_output_file avformat_alloc_output_context2(…

java comparator排序顺序_Java 集合排序策略接口 Comparator

1. 前言 最近用到了集合排序&#xff08;基于 Java 8&#xff09;。现在我能用 Stream 的就用 Stream &#xff0c;真香&#xff01;排序可以这么写&#xff1a; List<People> peoples new ArrayList<>();// 中间省略// 按照年龄从小到大排序 peoples.sort(Compar…

关闭IOS更新功能(ios4/5/6)

防止IOS升级&#xff1a; 工具&#xff1a;ifunbox 展开/System/Library/LaunchDaemons&#xff0c;将下面4个文件删除&#xff08;不推荐&#xff09;或者改名&#xff08;后缀也得改&#xff09;,改名后记得必须重启。 com.apple.mobile.softwareupdated.plist - OTA升级&…

TCP/IP、Http的区别

2019独角兽企业重金招聘Python工程师标准>>> TPC/IP协议是传输层协议&#xff0c;主要解决数据如何在网络中传输&#xff0c;而HTTP是应用层协议&#xff0c;主要解决如何包装数据。关于TCP/IP和HTTP协议的关系&#xff0c;网络有一段比较容易理解的介绍&#xff1a…

如何在Ubuntu下安装 monodevelop

参考介绍 http://www.monodevelop.com/download/linux/ 首先&#xff0c;Add the Mono Project GPG signing key sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF 其次&#xff0c;Add the package repository echo "d…

百度地图定位地址为空

在使用百度地图定位的时候&#xff0c; BDLocation 不为空&#xff0c;但是&#xff0c;城市&#xff0c;地址各个字段都为空&#xff0c;需要设置option.setAddrType("all");全部代码为&#xff1a; mLocClient new LocationClient(this);mLocClient.registerLocat…

小程序循环里做字符串拼接_昨天还在for循环里写加号拼接字符串的那个同事,今天已经不在了...

引言都说 StringBuilder 在处理字符串拼接上效率要强于 String&#xff0c;但有时候我们的理解可能会存在一定的偏差。最近我在测试数据导入效率的时候就发现我以前对 StringBuilder 的部分理解是错误的。后来我通过实践测试 找原理 的方式搞清楚了这块的逻辑。现在将过程分享…

【T-SQL系列】新的排序函数

【T-SQL系列】新的排序函数 原文:【T-SQL系列】新的排序函数如&#xff1a;ROW_NUMBER、RANK、DENSE_RANK三个分析函数都是按照col1分组内从1开始排序 ROW_NUMBER() 是没有重复值的排序(即使两天记录相等也是不重复的)&#xff0c;可以利用它来实现分页 DENSE_RANK() 是连续排序…

java mysql修改表结构字段_【开发技术】java+mysql 更改表字段的步骤

1).首先通过SQL更改MYSQL库中的表结构(下面是一些例子)ALTER TABLE illegalactivate ADD macethaddress varchar(250) NOT NULL;Alter TABLE illegalactivate drop primary key;ALTER TABLE illegalactivate ADD CONSTRAINT PK_illegalactivate PRIMARY KEY ( macaddress…

kbengine通讯协议

通讯协议格式 客户端想要与KBEngine进行通讯需要与KBEngine使用相同的协议&#xff0c;KBEngine通讯协议分为如下两种类型: 确定长度类型: |-----------------------------------------------------------------| Packet | Len: 2Bytes | Len: N …

Oracle中exp的使用2

在使用exp的时候&#xff0c;需要注意以下几点当前客户端版本、目标客户端的版本、注意需要设置字符集&#xff0c;也就是NLS_LANG 参考oracle字符集的设置NLS_LANG格式为&#xff1a;[NLS_LANGUAGE]_[NLS_TERRITORY].[NLS_CHARACTERSET].NLS_LANGUAGE指的是Oracle消息使用的语…

shell 编程(难题分析)

一、基础知识&#xff1a;http://www.aminglinux.com/bbs/thread-6833-1-1.html 一、grep用grep把passwd文档中包含root或者‘500’的行过滤出来&#xff0c;并在过滤出来的行前面加上行号.grep -n root\|500 passwdr.o 如r1o,rto都满足该条件&#xff0c;.表示匹配…