c#使用wmi查询usb设备信息示例

开发环境:Visual Studio V2010 .NET Framework 4 Client Profile

代码如下:

using System;
using System.Management;
using System.Text.RegularExpressions;
using System.Collections.Generic;

namespace Splash.IO.PORTS
{
/// <summary>
/// 即插即用设备信息结构
/// </summary>
public struct PnPEntityInfo
{
public String PNPDeviceID;  // 设备ID
public String Name; // 设备名称
public String Description;  // 设备描述
public String Service;  // 服务
public String Status;   // 设备状态
public UInt16 VendorID; // 供应商标识
public UInt16 ProductID;// 产品编号
public Guid ClassGuid;  // 设备安装类GUID
}

/// <summary>
/// 基于WMI获取USB设备信息
/// </summary>
public partial class USB

#region UsbDevice
/// <summary>
/// 获取所有的USB设备实体(过滤没有VID和PID的设备)
/// </summary>
public static PnPEntityInfo[] AllUsbDevices
{
get
{
return WhoUsbDevice(UInt16.MinValue, UInt16.MinValue, Guid.Empty);
}
}

/// <summary>
/// 查询USB设备实体(设备要求有VID和PID)
/// </summary>
/// <param name="VendorID">供应商标识,MinValue忽视</param>
/// <param name="ProductID">产品编号,MinValue忽视</param>
/// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>
/// <returns>设备列表</returns>
public static PnPEntityInfo[] WhoUsbDevice(UInt16 VendorID, UInt16 ProductID, Guid ClassGuid)
{
List<PnPEntityInfo> UsbDevices = new List<PnPEntityInfo>();

// 获取USB控制器及其相关联的设备实体
ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();
if (USBControllerDeviceCollection != null)
{
foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)
{   // 获取设备实体的DeviceID
String Dependent = (USBControllerDevice["Dependent"] as String).Split(new Char[] { '=' })[1];

// 过滤掉没有VID和PID的USB设备
Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
if (match.Success)
{
UInt16 theVendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识
if (VendorID != UInt16.MinValue && VendorID != theVendorID) continue;

UInt16 theProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
if (ProductID != UInt16.MinValue && ProductID != theProductID) continue;

ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();
if (PnPEntityCollection != null)
{
foreach (ManagementObject Entity in PnPEntityCollection)
{
Guid theClassGuid = new Guid(Entity["ClassGuid"] as String);// 设备安装类GUID
if (ClassGuid != Guid.Empty && ClassGuid != theClassGuid) continue;

PnPEntityInfo Element;
Element.PNPDeviceID = Entity["PNPDeviceID"] as String;  // 设备ID
Element.Name = Entity["Name"] as String;// 设备名称
Element.Description = Entity["Description"] as String;  // 设备描述
Element.Service = Entity["Service"] as String;  // 服务
Element.Status = Entity["Status"] as String;// 设备状态
Element.VendorID = theVendorID; // 供应商标识
Element.ProductID = theProductID;   // 产品编号
Element.ClassGuid = theClassGuid;   // 设备安装类GUID

UsbDevices.Add(Element);
}
}
}
}
}

if (UsbDevices.Count == 0) return null; else return UsbDevices.ToArray();
}

/// <summary>
/// 查询USB设备实体(设备要求有VID和PID)
/// </summary>
/// <param name="VendorID">供应商标识,MinValue忽视</param>
/// <param name="ProductID">产品编号,MinValue忽视</param>
/// <returns>设备列表</returns>
public static PnPEntityInfo[] WhoUsbDevice(UInt16 VendorID, UInt16 ProductID)
{
return WhoUsbDevice(VendorID, ProductID, Guid.Empty);
}

/// <summary>
/// 查询USB设备实体(设备要求有VID和PID)
/// </summary>
/// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>
/// <returns>设备列表</returns>
public static PnPEntityInfo[] WhoUsbDevice(Guid ClassGuid)
{
return WhoUsbDevice(UInt16.MinValue, UInt16.MinValue, ClassGuid);
}

/// <summary>
/// 查询USB设备实体(设备要求有VID和PID)
/// </summary>
/// <param name="PNPDeviceID">设备ID,可以是不完整信息</param>
/// <returns>设备列表</returns>
public static PnPEntityInfo[] WhoUsbDevice(String PNPDeviceID)
{
List<PnPEntityInfo> UsbDevices = new List<PnPEntityInfo>();

// 获取USB控制器及其相关联的设备实体
ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();
if (USBControllerDeviceCollection != null)
{
foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)
{   // 获取设备实体的DeviceID
String Dependent = (USBControllerDevice["Dependent"] as String).Split(new Char[] { '=' })[1];
if (!String.IsNullOrEmpty(PNPDeviceID))
{   // 注意:忽视大小写
if (Dependent.IndexOf(PNPDeviceID, 1, PNPDeviceID.Length - 2, StringComparison.OrdinalIgnoreCase) == -1) continue;
}

// 过滤掉没有VID和PID的USB设备
Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
if (match.Success)
{
ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();
if (PnPEntityCollection != null)
{
foreach (ManagementObject Entity in PnPEntityCollection)
{
PnPEntityInfo Element;
Element.PNPDeviceID = Entity["PNPDeviceID"] as String;  // 设备ID
Element.Name = Entity["Name"] as String;// 设备名称
Element.Description = Entity["Description"] as String;  // 设备描述
Element.Service = Entity["Service"] as String;  // 服务
Element.Status = Entity["Status"] as String;// 设备状态
Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识  
Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号 // 产品编号
Element.ClassGuid = new Guid(Entity["ClassGuid"] as String);// 设备安装类GUID

UsbDevices.Add(Element);
}
}
}
}
}

if (UsbDevices.Count == 0) return null; else return UsbDevices.ToArray();
}

/// <summary>
/// 根据服务定位USB设备
/// </summary>
/// <param name="ServiceCollection">要查询的服务集合</param>
/// <returns>设备列表</returns>
public static PnPEntityInfo[] WhoUsbDevice(String[] ServiceCollection)
{
if (ServiceCollection == null || ServiceCollection.Length == 0)
return WhoUsbDevice(UInt16.MinValue, UInt16.MinValue, Guid.Empty);

List<PnPEntityInfo> UsbDevices = new List<PnPEntityInfo>();

// 获取USB控制器及其相关联的设备实体
ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();
if (USBControllerDeviceCollection != null)
{
foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)
{   // 获取设备实体的DeviceID
String Dependent = (USBControllerDevice["Dependent"] as String).Split(new Char[] { '=' })[1];

// 过滤掉没有VID和PID的USB设备
Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
if (match.Success)
{
ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();
if (PnPEntityCollection != null)
{
foreach (ManagementObject Entity in PnPEntityCollection)
{
String theService = Entity["Service"] as String;  // 服务
if (String.IsNullOrEmpty(theService)) continue;

foreach (String Service in ServiceCollection)
{   // 注意:忽视大小写
if (String.Compare(theService, Service, true) != 0) continue;

PnPEntityInfo Element;
Element.PNPDeviceID = Entity["PNPDeviceID"] as String;  // 设备ID
Element.Name = Entity["Name"] as String;// 设备名称
Element.Description = Entity["Description"] as String;  // 设备描述
Element.Service = theService;   // 服务
Element.Status = Entity["Status"] as String;// 设备状态
Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识  
Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
Element.ClassGuid = new Guid(Entity["ClassGuid"] as String);// 设备安装类GUID

UsbDevices.Add(Element);
break;
}
}
}
}
}
}

if (UsbDevices.Count == 0) return null; else return UsbDevices.ToArray();
}
#endregion

#region PnPEntity
/// <summary>
/// 所有即插即用设备实体(过滤没有VID和PID的设备)
/// </summary>
public static PnPEntityInfo[] AllPnPEntities
{
get
{
return WhoPnPEntity(UInt16.MinValue, UInt16.MinValue, Guid.Empty);
}
}

/// <summary>
/// 根据VID和PID及设备安装类GUID定位即插即用设备实体
/// </summary>
/// <param name="VendorID">供应商标识,MinValue忽视</param>
/// <param name="ProductID">产品编号,MinValue忽视</param>
/// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>
/// <returns>设备列表</returns>
/// <remarks>
/// HID:{745a17a0-74d3-11d0-b6fe-00a0c90f57da}
/// Imaging Device:{6bdd1fc6-810f-11d0-bec7-08002be2092f}
/// Keyboard:{4d36e96b-e325-11ce-bfc1-08002be10318}
/// Mouse:{4d36e96f-e325-11ce-bfc1-08002be10318}
/// Network Adapter:{4d36e972-e325-11ce-bfc1-08002be10318}
/// USB:{36fc9e60-c465-11cf-8056-444553540000}
/// </remarks>
public static PnPEntityInfo[] WhoPnPEntity(UInt16 VendorID, UInt16 ProductID, Guid ClassGuid)
{
List<PnPEntityInfo> PnPEntities = new List<PnPEntityInfo>();

// 枚举即插即用设备实体
String VIDPID;
if (VendorID == UInt16.MinValue)
{
if (ProductID == UInt16.MinValue)
VIDPID = "'%VID[_]____&PID[_]____%'";
else
VIDPID = "'%VID[_]____&PID[_]" + ProductID.ToString("X4") + "%'";  
}
else
{
if (ProductID == UInt16.MinValue)
VIDPID = "'%VID[_]" + VendorID.ToString("X4") + "&PID[_]____%'";
else
VIDPID = "'%VID[_]" + VendorID.ToString("X4") + "&PID[_]" + ProductID.ToString("X4") + "%'";
}

String QueryString;
if (ClassGuid == Guid.Empty)
QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE" + VIDPID;
else
QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE" + VIDPID + " AND ClassGuid='" + ClassGuid.ToString("B") + "'";

ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher(QueryString).Get();
if (PnPEntityCollection != null)
{
foreach (ManagementObject Entity in PnPEntityCollection)
{
String PNPDeviceID = Entity["PNPDeviceID"] as String;
Match match = Regex.Match(PNPDeviceID, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
if (match.Success)
{
PnPEntityInfo Element;

Element.PNPDeviceID = PNPDeviceID;  // 设备ID
Element.Name = Entity["Name"] as String;// 设备名称
Element.Description = Entity["Description"] as String;  // 设备描述
Element.Service = Entity["Service"] as String;  // 服务
Element.Status = Entity["Status"] as String;// 设备状态
Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识
Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
Element.ClassGuid = new Guid(Entity["ClassGuid"] as String);// 设备安装类GUID

PnPEntities.Add(Element);
}
}
}

if (PnPEntities.Count == 0) return null; else return PnPEntities.ToArray();
}

/// <summary>
/// 根据VID和PID定位即插即用设备实体
/// </summary>
/// <param name="VendorID">供应商标识,MinValue忽视</param>
/// <param name="ProductID">产品编号,MinValue忽视</param>
/// <returns>设备列表</returns>
public static PnPEntityInfo[] WhoPnPEntity(UInt16 VendorID, UInt16 ProductID)
{
return WhoPnPEntity(VendorID, ProductID, Guid.Empty);
}

/// <summary>
/// 根据设备安装类GUID定位即插即用设备实体
/// </summary>
/// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>
/// <returns>设备列表</returns>
public static PnPEntityInfo[] WhoPnPEntity(Guid ClassGuid)
{
return WhoPnPEntity(UInt16.MinValue, UInt16.MinValue, ClassGuid);
}

/// <summary>
/// 根据设备ID定位设备
/// </summary>
/// <param name="PNPDeviceID">设备ID,可以是不完整信息</param>
/// <returns>设备列表</returns>
/// <remarks>
/// 注意:对于下划线,需要写成“[_]”,否则视为任意字符
/// </remarks>
public static PnPEntityInfo[] WhoPnPEntity(String PNPDeviceID)
{
List<PnPEntityInfo> PnPEntities = new List<PnPEntityInfo>();

// 枚举即插即用设备实体
String QueryString;
if (String.IsNullOrEmpty(PNPDeviceID))
{
QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%VID[_]____&PID[_]____%'";
}
else
{   // LIKE子句中有反斜杠字符将会引发WQL查询异常
QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%" + PNPDeviceID.Replace('\\', '_') + "%'";
}

ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher(QueryString).Get();
if (PnPEntityCollection != null)
{
foreach (ManagementObject Entity in PnPEntityCollection)
{
String thePNPDeviceID = Entity["PNPDeviceID"] as String;
Match match = Regex.Match(thePNPDeviceID, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
if (match.Success)
{
PnPEntityInfo Element;

Element.PNPDeviceID = thePNPDeviceID;   // 设备ID
Element.Name = Entity["Name"] as String;// 设备名称
Element.Description = Entity["Description"] as String;  // 设备描述
Element.Service = Entity["Service"] as String;  // 服务
Element.Status = Entity["Status"] as String;// 设备状态
Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识
Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
Element.ClassGuid = new Guid(Entity["ClassGuid"] as String);// 设备安装类GUID

PnPEntities.Add(Element);
}
}
}

if (PnPEntities.Count == 0) return null; else return PnPEntities.ToArray();
}

/// <summary>
/// 根据服务定位设备
/// </summary>
/// <param name="ServiceCollection">要查询的服务集合,null忽视</param>
/// <returns>设备列表</returns>
/// <remarks>
/// 跟服务相关的类:
/// Win32_SystemDriverPNPEntity
/// Win32_SystemDriver
/// </remarks>
public static PnPEntityInfo[] WhoPnPEntity(String[] ServiceCollection)
{
if (ServiceCollection == null || ServiceCollection.Length == 0)
return WhoPnPEntity(UInt16.MinValue, UInt16.MinValue, Guid.Empty);

List<PnPEntityInfo> PnPEntities = new List<PnPEntityInfo>();

// 枚举即插即用设备实体
String QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%VID[_]____&PID[_]____%'";
ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher(QueryString).Get();
if (PnPEntityCollection != null)
{
foreach (ManagementObject Entity in PnPEntityCollection)
{
String PNPDeviceID = Entity["PNPDeviceID"] as String;
Match match = Regex.Match(PNPDeviceID, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
if (match.Success)
{
String theService = Entity["Service"] as String;// 服务
if (String.IsNullOrEmpty(theService)) continue;

foreach (String Service in ServiceCollection)
{   // 注意:忽视大小写
if (String.Compare(theService, Service, true) != 0) continue;

PnPEntityInfo Element;

Element.PNPDeviceID = PNPDeviceID;  // 设备ID
Element.Name = Entity["Name"] as String;// 设备名称
Element.Description = Entity["Description"] as String;  // 设备描述
Element.Service = theService;   // 服务
Element.Status = Entity["Status"] as String;// 设备状态
Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识
Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
Element.ClassGuid = new Guid(Entity["ClassGuid"] as String);// 设备安装类GUID

PnPEntities.Add(Element);
break;
}
}
}
}

if (PnPEntities.Count == 0) return null; else return PnPEntities.ToArray();
}
#endregion
}
}

(0)

相关推荐

  • C#获取USB事件API实例分析

    本文实例讲述了C#获取USB事件API.分享给大家供大家参考.具体如下: const int WM_DEVICECHANGE = 0x2190; const int DBT_DEVICEARRIVAL = 0x8000; const int DBT_DEVICEREMOVECOMPLETE = 0x8004; protected override void WndProc(ref Message m) { try { //if (m.Msg == WM_DEVICECHANGE) //{ swi

  • C#实现快递api接口调用方法

    无平台限制,依赖于快递api网接口 ----------------实体类 [DataContract] public class SyncResponseEntity { public SyncResponseEntity() { } /// <summary> /// 需要查询的快递代号 /// </summary> [DataMember(Order = 0, Name = "id")] public string ID { get; set; } ///

  • C#通过WIN32 API实现嵌入程序窗体

    本文实例讲述了C#通过WIN32 API实现嵌入程序窗体的方法,分享给大家供大家参考.具体如下: 这是一个不使用COM,而是通过WIN32 API实现的示例, 它把写字板程序嵌在了自己的一个面板中. 这么做可能没有实际意义, 因为两个程序之前没有进行有价值的交互, 这里仅仅是为了演示这么做到, 以下是详细注释过的主要源代码. 我们把它封装到一个类中: using System; using System.Collections.Generic; using System.Linq; using

  • c#封装百度web服务geocoding api 、百度坐标转换示例

    1.创建基础参数类 复制代码 代码如下: public static class BaiduConstParams    {        public const string PlaceApIv2Search = "http://api.map.baidu.com/place/v2/search";        public const string PlaceApIv2Detail = "http://api.map.baidu.com/place/v2/detail

  • C#开发纽曼USB来电小秘书客户端总结

    在使用C#开发完CRM的来电弹屏之后,有些客户有了新的要求,他们希望不但能够实现来电弹屏,更希望能够将呼入呼出的电话录音并上传到CRM服务器上,方便日后跟踪记录.于是便有了来电小秘书客户端的开发. 本文所述的来电小秘书客户端的开发是基于纽曼USB来电通客户端的基础上进行开发的,由于纽曼USB来电通的硬件没有录音功能,于是硬件上使用了纽曼的另一个硬件产品来电小秘书,虽然是同一个厂家的产品,可是它们的API却是完全不兼容,更烦的是,来电小秘书API没有来电的回调接口,无法通过回调触发程序,也没有C#

  • C#调用windows api关机(关机api)示例代码分享

    复制代码 代码如下: using System;using System.Runtime.InteropServices; class shoutdown{ [StructLayout(LayoutKind.Sequential, Pack=1)] internal struct TokPriv1Luid { public int Count; public long Luid; public int Attr; } [DllImport("kernel32.dll", ExactSp

  • c#检测usb设备拨插类库USBClassLibrary分享

    复制代码 代码如下: private void USBPort_USBDeviceAttached(objectsender,USBClass.USBDeviceEventArgs e){if (!MyUSBDeviceConnected){if(USBClass.GetUSBDevice(MyDeviceVID, MyDevicePID,ref USBDeviceProperties, false)){ //My Device is connectedMyUSBDeviceConnected

  • c# xml API操作的小例子

    复制代码 代码如下: LoginInfo loginInfo = new LoginInfo();xmlNode = _xml.SelectSingleNode(loginUrl);loginInfo.LoginUrl = xmlNode.InnerText;xmlNode = _xml.SelectSingleNode(loginUser);loginInfo.UserId = xmlNode.Attributes["tagId"].Value;loginInfo.UserValue

  • c#使用wmi查询usb设备信息示例

    开发环境:Visual Studio V2010 .NET Framework 4 Client Profile 复制代码 代码如下: using System;using System.Management;using System.Text.RegularExpressions;using System.Collections.Generic; namespace Splash.IO.PORTS{/// <summary>/// 即插即用设备信息结构/// </summary>

  • Android中查看USB连接的外接设备信息的代码实例

    1,USB存储设备(如:U盘,移动硬盘): //USB存储设备 插拔监听与 SD卡插拔监听一致. 复制代码 代码如下: private USBBroadCastReceiver mBroadcastReceiver; IntentFilter iFilter = new IntentFilter();       iFilter.addAction(Intent.ACTION_MEDIA_EJECT);       iFilter.addAction(Intent.ACTION_MEDIA_MO

  • Android usb设备权限查询及自动获取详解流程

    看到当上面的对话框弹出时,可以使用命令查看顶层的活动窗口 adb shell dumpsys window | findstr mCurrentFocus mCurrentFocus=Window{41ab0ee0 u0 com.android.systemui/com.android.systemui.usb.UsbPermissionActivity} 这就是应用的位置,当然我们也可以是用grep命令来查找这个对话框的.xml文件,进入android源码然后输入命令: grep '默认情况下

  • PHP获取访问设备信息的方法示例

    本文实例讲述了PHP获取访问设备信息的方法.分享给大家供大家参考,具体如下: <?php header("Content:Content-type:text/html;charset=utf-8"); // // 作用取得客户端的ip.地理位置.浏览器.以及访问设备 class get_equipment_info{ ////获得访客浏览器类型 function GetBrowser(){ if(!empty($_SERVER['HTTP_USER_AGENT'])) { $br

  • Linux如何使用libudev获取USB设备VID及PID

    在本文将使用libudev库来访问hidraw的设备.通过libudev库,我们可以查询设备的厂家ID(Vendor ID, VID),产品ID(Product ID, PID),序列号和设备字符串等而不需要打开设备.进一步,libudev可以告诉我们在/dev目录下设备节点的具体位置路径,为应用程序提供一种具有足够鲁棒性而又和系统厂家独立的访问设备的方式.使用libudev库,需要包含libudev.h头文件,并且在编译时加上-ludev告诉编译器去链接udev库. 将列出当前连接在系统中的所

  • Linux常用查看硬件设备信息命令大全(值得收藏)

    # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # 查看CPU信息 # hostname # 查看计算机名 # lspci -tv # 列出所有PCI设备 # lsusb -tv # 列出所有USB设备 # lsmod # 列出加载的内核模块 # env # 查看环境变量 资源 # free -m # 查看内存使用量和交换区使用量 # df -h # 查看各分区使用情况 # du

  • Powershell小技巧之使用WMI查询插上的U盘

    如果你想知道当前插在你电脑上的USB设备,WMI能帮助你: Get-WmiObject -Class Win32_PnPEntity | Where-Object { $_.DeviceID -like 'USBSTOR*' } 这将返回所有插上在使用的USBSTOR设备类 如果你使用WMI查询语言(WQL),你甚至可以使用筛选命令: Get-WmiObject -Query 'Select * From Win32_PnPEntity where DeviceID Like "USBSTOR%

  • 在linux下实现 python 监控usb设备信号

    1. linux下消息记录 关于系统的各种消息一般都会记录在/var/log/messages文件中,有些主机在中默认情况下有可能没有启用,具体配置方法可参考下面这篇博客: 系统日志配置 /var/log/messages 2. python 代码实现 原理其实很简单,就是读/var/log/messages文件,找到有关usb的信息就可以了. #!/usr/bin/env python usbmsg = open("/var/log/messages", "r")

  • Asp.Net Core 调用第三方Open API查询物流数据的示例

    在我们的业务中不可避免要与第三方的系统进行交互,调用他们提供的API来获取相应的数据,那么对于这样的情况该怎样进行处理呢?下面就结合自己对接跨越速运接口来获取一个发运单完整的物流信息为例来说明如何在Asp.Net Core中通过代码实现.当然在他们的官方网站上面会给出具体的API调用方式以及参数格式,作为调用方只需要根据相应规则来进行编码即可,下面以我们查询某一个具体的发运单的物流信息为例来进行说明. 下面以一个查询路由详细信息为例来进行说明.当前接口主要包括:1 概述. 2 系统参数. 3 

  • Mybatis-Plus根据时间段去查询数据的实现示例

    业务需求:在前端界面选择开始时间.结束时间,后台根据拿到的开始.结束时间去数据库中查询该段时间的数据集返回给前端界面. 1.前端我使用的是elementUI和vue框架,最好是在前端界面进行一个简单的校验规则,对比一下开始时间和结束时间的大小,校验的代码很简单,直接在触发查询按钮的函数前面加入校验即可.代码如下: if(this.StafPsnClctDetlDFormQuery.startTime >= this.StafPsnClctDetlDFormQuery.endTime){ this

随机推荐