Delphi调用WMI读取USB设备的PID和VID


本文整理自网络,侵删。

 
WMI(Windows?Management Instrumentation ) 非常强大,它可以以数据库的形式查询你的电脑的软件和硬件,在它的数据库里面,时刻保存着最新的软件信息和硬件信息,因此你可以用WMI来检测CUP主频、温度,读取WINDOWS的进程.........
  本文就介绍如何使用WMI读取USB设备的PID和VID码

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls,ActiveX, ComObj;



procedure TForm1.Button2Click(Sender: TObject);

var

Locator: OleVariant;

WMI: OleVariant;

RET: OleVariant;

Enum: IEnumVariant;

Tmp: OleVariant;

Value: Cardinal;

begin;

Locator := CreateOleObject('WbemScripting.SWbemLocator');

WMI := Locator.ConnectServer('.', '', '', '');

Ret := WMI.ExecQuery('SELECT * FROM Win32_USBHub');//这里Win32_USBHub为检测项,详见下表



Enum:= IUnknown(RET._NewEnum) as IEnumVariant;

while (Enum.Next(1, Tmp, Value) = S_OK) do

begin

  if Tmp.Name='USB Mass Storage Device' then

     ShowMessage('这个u盘的硬件特征码是'+Tmp.PNPDeviceID);//Tmp为检测到返回的数据集合,其中PNPDeviceID为集合中的对象,包含了PID和VID码

end;



end;



Win32_USBHub只是冰山一角,常用的还有以下



  "Win32_1394Controller"                ,

  "Win32_BaseBoard"                     ,

  "Win32_Battery"                       ,

  "Win32_BIOS"                          ,

  "Win32_Bus"                           ,

  "Win32_CacheMemory"                   ,

  "Win32_CDROMDrive"                    ,

  "Win32_CurrentProbe"                  ,

  "Win32_DesktopMonitor"                ,

  "Win32_DeviceMemoryAddress"           ,

  "Win32_DiskDrive"                     ,

  "Win32_DisplayConfiguration"          ,

  "Win32_DisplayControllerConfiguration",

  "Win32_DMAChannel"                    ,

  "Win32_Fan"                           ,

  "Win32_FloppyController"              ,

  "Win32_FloppyDrive"                   ,

  "Win32_HeatPipe"                      ,

  "Win32_IDEController"                 ,

  "Win32_InfraredDevice"                ,

  "Win32_IRQResource"                   ,

  "Win32_Keyboard"                      ,

  "Win32_MemoryArray"                   ,

  "Win32_MemoryDevice"                  ,

  "Win32_MotherboardDevice"             ,

  "Win32_NetworkAdapter"                ,

  "Win32_NetworkAdapterConfiguration"   ,

  "Win32_OnBoardDevice"                 ,

  "Win32_ParallelPort"                  ,

  "Win32_PCMCIAController"              ,

  "Win32_PhysicalMemory"                ,

  "Win32_PhysicalMemoryArray"           ,

  "Win32_PnPEntity"                     ,

  "Win32_PointingDevice"                ,

  "Win32_PortableBattery"               ,

  "Win32_PortConnector"                 ,

  "Win32_PortResource"                  ,

  "Win32_POTSModem"                     ,

  "Win32_PowerManagementEvent"          ,

  "Win32_Printer"                       ,

  "Win32_PrinterConfiguration"          ,

  "Win32_PrintJob"                      ,

  "Win32_Processor"                     ,

  "Win32_Refrigeration"                 ,

  "Win32_SerialPort"                    ,

  "Win32_SerialPortConfiguration"       ,

  "Win32_SMBIOSMemory"                  ,

  "Win32_SoundDevice"                   ,

  "Win32_SystemEnclosure"               ,

  "Win32_SystemMemoryResource"          ,

  "Win32_SystemSlot"                    ,

  "Win32_TapeDrive"                     ,

  "Win32_TemperatureProbe"              ,

  "Win32_UninterruptiblePowerSupply"    ,

  "Win32_USBController"                 ,

  "Win32_VideoConfiguration"            ,

  "Win32_VideoController"               ,

  "Win32_VoltageProbe"                  ,

相关阅读 >>

Delphi 安卓获得设备 id

Delphi date 返回当前的日期

Delphi opendialog设置默认打开路径

Delphi firedac 下的 sqlite [8] - 自定义函数

Delphi firemonkey移动应用程序将设置保存到ini文件的示例

Delphi 文件路径相关的字符串操作

如何用Delphi实现windows xp中“本地连接”的启用和禁用

Delphi中webbrowser的用法

Delphi inc函数和dec函数的用法

Delphi tpath

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...