C# 根据USB设备VID和PID 获取设备总线已报告设备描述

2024-02-02 00:12

本文主要是介绍C# 根据USB设备VID和PID 获取设备总线已报告设备描述,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

总线已报告设备描述   DEVPKEY_Device_BusReportedDeviceDesc

模式 winform 语言 c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace testusb
{public partial class Form1 : Form{[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]static extern IntPtr SetupDiGetClassDevs(ref Guid classGuid, string enumerator, IntPtr hwndParent, uint flags);[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]static extern bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, uint memberIndex, ref SP_DEVINFO_DATA deviceInfoData);[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]static extern bool SetupDiGetDeviceProperty(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData, ref DEVPROPKEY propertyKey, out int propertyType, IntPtr propertyBuffer, int propertyBufferSize, out int requiredSize, int flags);[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]static extern bool SetupDiDestroyDeviceInfoList(IntPtr deviceInfoSet);[StructLayout(LayoutKind.Sequential)]struct SP_DEVINFO_DATA{public int cbSize;public Guid classGuid;public int devInst;public IntPtr reserved;}[StructLayout(LayoutKind.Sequential)]struct DEVPROPKEY{public Guid fmtid;public uint pid;}public Form1(){InitializeComponent();}//按钮事件private void button1_Click(object sender, EventArgs e){// USB 设备的 Vendor ID (VID) 和 Product ID (PID)string vid = "0xFFFF";  //这边写你usb设备的vidstring pid = "0x0100"; //这边写你usb设备的pidGuid guid = new Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED"); // USB 设备类的 GUIDIntPtr deviceInfoSet = SetupDiGetClassDevs(ref guid, null, IntPtr.Zero, 0x12);if (deviceInfoSet.ToInt64() != -1){SP_DEVINFO_DATA devInfoData = new SP_DEVINFO_DATA();devInfoData.cbSize = Marshal.SizeOf(devInfoData);for (uint i = 0; SetupDiEnumDeviceInfo(deviceInfoSet, i, ref devInfoData); i++){DEVPROPKEY propertyKey = new DEVPROPKEY();propertyKey.fmtid = new Guid("540b947e-8b40-45bc-a8a2-6a0b894cbda2"); // DEVPKEY_Device_BusReportedDeviceDesc 的格式 IDpropertyKey.pid = 4; // DEVPKEY_Device_BusReportedDeviceDesc 的属性 IDint propertyType;int requiredSize;// 获取设备属性值的大小SetupDiGetDeviceProperty(deviceInfoSet, ref devInfoData, ref propertyKey, out propertyType, IntPtr.Zero, 0, out requiredSize, 0);IntPtr propertyBuffer = Marshal.AllocHGlobal(requiredSize);if (SetupDiGetDeviceProperty(deviceInfoSet, ref devInfoData, ref propertyKey, out propertyType, propertyBuffer, requiredSize, out requiredSize, 0)){string propertyValue = Marshal.PtrToStringUni(propertyBuffer);Console.WriteLine("Device Description: " + propertyValue);}Marshal.FreeHGlobal(propertyBuffer);}SetupDiDestroyDeviceInfoList(deviceInfoSet);}}}
}

执行结果

电脑上的设备

这篇关于C# 根据USB设备VID和PID 获取设备总线已报告设备描述的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/668905

相关文章

2. c#从不同cs的文件调用函数

1.文件目录如下: 2. Program.cs文件的主函数如下 using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using System.Windows.Forms;namespace datasAnalysis{internal static

【专题】2024飞行汽车技术全景报告合集PDF分享(附原数据表)

原文链接: https://tecdat.cn/?p=37628 6月16日,小鹏汇天旅航者X2在北京大兴国际机场临空经济区完成首飞,这也是小鹏汇天的产品在京津冀地区进行的首次飞行。小鹏汇天方面还表示,公司准备量产,并计划今年四季度开启预售小鹏汇天分体式飞行汽车,探索分体式飞行汽车城际通勤。阅读原文,获取专题报告合集全文,解锁文末271份飞行汽车相关行业研究报告。 据悉,业内人士对飞行汽车行业

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

用命令行的方式启动.netcore webapi

用命令行的方式启动.netcore web项目 进入指定的项目文件夹,比如我发布后的代码放在下面文件夹中 在此地址栏中输入“cmd”,打开命令提示符,进入到发布代码目录 命令行启动.netcore项目的命令为:  dotnet 项目启动文件.dll --urls="http://*:对外端口" --ip="本机ip" --port=项目内部端口 例: dotnet Imagine.M

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能

如何编写Linux PCIe设备驱动器 之二

如何编写Linux PCIe设备驱动器 之二 功能(capability)集功能(capability)APIs通过pci_bus_read_config完成功能存取功能APIs参数pos常量值PCI功能结构 PCI功能IDMSI功能电源功率管理功能 功能(capability)集 功能(capability)APIs int pcie_capability_read_wo

Android Environment 获取的路径问题

1. 以获取 /System 路径为例 /*** Return root of the "system" partition holding the core Android OS.* Always present and mounted read-only.*/public static @NonNull File getRootDirectory() {return DIR_ANDR

Python:豆瓣电影商业数据分析-爬取全数据【附带爬虫豆瓣,数据处理过程,数据分析,可视化,以及完整PPT报告】

**爬取豆瓣电影信息,分析近年电影行业的发展情况** 本文是完整的数据分析展现,代码有完整版,包含豆瓣电影爬取的具体方式【附带爬虫豆瓣,数据处理过程,数据分析,可视化,以及完整PPT报告】   最近MBA在学习《商业数据分析》,大实训作业给了数据要进行数据分析,所以先拿豆瓣电影练练手,网络上爬取豆瓣电影TOP250较多,但对于豆瓣电影全数据的爬取教程很少,所以我自己做一版。 目

C# dateTimePicker 显示年月日,时分秒

dateTimePicker默认只显示日期,如果需要显示年月日,时分秒,只需要以下两步: 1.dateTimePicker1.Format = DateTimePickerFormat.Time 2.dateTimePicker1.CustomFormat = yyyy-MM-dd HH:mm:ss Tips:  a. dateTimePicker1.ShowUpDown = t

C#关闭指定时间段的Excel进程的方法

private DateTime beforeTime;            //Excel启动之前时间          private DateTime afterTime;               //Excel启动之后时间          //举例          beforeTime = DateTime.Now;          Excel.Applicat