HardBirch

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

时间:07-07-17 栏目:安卓入门与提高 作者:张飞不张,文采横飞 评论:4 点击: 3,244 次

 


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调用WMI读取USB设备的PID和VID

Delphi调用WMI读取USB设备的PID和VID:目前有4 条留言

  1. 4楼
    fsljz:

    good

    2008-04-28 18:26 [回复]
  2. 地板
    jedxu:

    请问如何通过wmi修改DNS的A记录。3ks.

    2008-04-30 08:13 [回复]
  3. 板凳
    forverlove:

    我能从不同的uSB设备实别出,是哪个设备输入了数据么?
    我有不同的USB设备,比键盘,标尺,我想实别这两个中的到底是哪一个输入了数据。

    2008-09-08 14:48 [回复]
  4. 沙发
    hellogv:

    当有设备插入时,就判断设备的特征码存储在注册表的哪个位置,并且注册表会有数据说明该设备是什么设备。

    2008-09-08 18:35 [回复]

发表评论


QQ群互动

Linux系统与内核学习群:194051772

WP建站技术学习交流群:194062106

魔豆之路QR

魔豆的Linux内核之路

魔豆的Linux内核之路

优秀工程师当看优秀书籍

优秀程序员,要看优秀书!

赞助商广告

友荐云推荐