我想读取连接到Windows10的USB摄像头(即HD摄像头)的名称,并将该名称作为变量存储在C#中。
发布于 2019-02-28 09:37:26
您可以尝试过滤Win32_PnPEntity
类中的项目,使其仅显示与图像或媒体类别相关的项目,这些类别通常列出与连接到U盘的摄像头相关的项目。
在SQL命令中,您可以更改类别。
using System.Management;
private static void GetUSBDevices()
{
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')");
foreach (var device in searcher.Get())
{
Console.WriteLine($"Device: {device["PNPClass"]} / {device["Caption"]}");
}
}
您需要将System.Management依赖项添加到项目中。
https://stackoverflow.com/questions/54915919
复制相似问题