C# 如何从Win32_CDROMDrive WMI类获取接口类型?
我已经实现了的目标,但在WMI类中不存在该属性(InterfaceType) 如何获取光盘驱动器的接口类型?是否存在另一种获得它的方法C# 如何从Win32_CDROMDrive WMI类获取接口类型?,c#,.net,wmi,C#,.net,Wmi,我已经实现了的目标,但在WMI类中不存在该属性(InterfaceType) 如何获取光盘驱动器的接口类型?是否存在另一种获得它的方法 提前感谢。您可以从DeviceID或PNPDeviceID属性中提取接口类型 试试这个样品 using System; using System.Collections.Generic; using System.Management; using System.Text; namespace GetWMI_Info { class Program
提前感谢。您可以从
DeviceID
或PNPDeviceID
属性中提取接口类型
试试这个样品
using System;
using System.Collections.Generic;
using System.Management;
using System.Text;
namespace GetWMI_Info
{
class Program
{
static void Main(string[] args)
{
try
{
ManagementScope Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", "localhost"), null);
Scope.Connect();
ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_CDROMDrive");
ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query);
foreach (ManagementObject WmiObject in Searcher.Get())
{
String InterfaceType = ((String)WmiObject["DeviceID"]).Substring(0, ((String)WmiObject["DeviceID"]).IndexOf(@"\"));
Console.WriteLine("{0,-35} {1,-40}", "InterfaceType", InterfaceType);
Console.WriteLine("{0,-35} {1,-40}","Drive",WmiObject["Drive"]);
Console.WriteLine("{0,-35} {1,-40}","Name",WmiObject["Name"]);
}
}
catch (Exception e)
{
Console.WriteLine(String.Format("Exception {0} Trace {1}",e.Message,e.StackTrace));
}
Console.WriteLine("Press Enter to exit");
Console.Read();
}
}
}
如果您在CD-ROM界面上运行Win32_DiskDrive,会发生什么情况?@RobertHarvey,它只显示计算机上安装的实际硬盘驱动器。嗯,我认为您无法从该类中获得它。如果您检查PNPDeviceID的前3个字符,您可以判断它是否是USB,但仅此而已。看见