程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi調用WMI讀取USB設備的PID和VID

Delphi調用WMI讀取USB設備的PID和VID

編輯:Delphi

WMI(Windows®Management Instrumentation ) 非常強大,它可以以數據庫的形式查詢你的電腦的軟件和硬件,在它的數據庫裡面,時刻保存著最新的軟件信息和硬件信息,因此你可以用WMI來檢測CUP 主頻、溫度,讀取WINDOWS的進程.........

本文就介紹如何使用WMI讀取USB設備的PID和VID碼

1. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
2.
3.   Dialogs, StdCtrls, ExtCtrls,ActiveX, ComObj;
4.
5.
6.
7. procedure TForm1.Button2Click(Sender: TObject);
8.
9. var
10.
11. Locator: OleVariant;
12.
13. WMI: OleVariant;
14.
15. RET: OleVariant;
16.
17. Enum: IEnumVariant;
18.
19. Tmp: OleVariant;
20.
21. Value: Cardinal;
22.
23. begin;
24.
25. Locator := CreateOleObject('WbemScripting.SWbemLocator');
26.
27. WMI := Locator.ConnectServer('.', '', '', '');
28.
29. Ret := WMI.ExecQuery('SELECT * FROM Win32_USBHub');//這裡Win32_USBHub為檢測項,詳見下表
30.
31.
32.
33. Enum:= IUnknown(RET._NewEnum) as IEnumVariant;
34.
35. while (Enum.Next(1, Tmp, Value) = S_OK) do
36.
37. begin
38.
39.   if Tmp.Name='USB Mass Storage Device' then
40.
41.      ShowMessage('這個u盤的硬件特征碼是'+Tmp.PNPDeviceID);//Tmp為檢測到返回的數據集合,其中PNPDeviceID為集合中的對象,包含了PID和VID碼
42.
43. end;
44.
45.
46.
47. end;
48.
49.
50.
51. Win32_USBHub只是冰山一角,常用的還有以下
52.
53.
54.
55.   "Win32_1394Controller"                ,
56.
57.   "Win32_BaseBoard"                     ,
58.
59.   "Win32_Battery"                       ,
60.
61.   "Win32_BIOS"                          ,
62.
63.   "Win32_Bus"                           ,
64.
65.   "Win32_CacheMemory"                   ,
66.
67.   "Win32_CDROMDrive"                    ,
68.
69.   "Win32_CurrentProbe"                  ,
70.
71.   "Win32_DesktopMonitor"                ,
72.
73.   "Win32_DeviceMemoryAddress"           ,
74.
75.   "Win32_DiskDrive"                     ,
76.
77.   "Win32_DisplayConfiguration"          ,
78.
79.   "Win32_DisplayControllerConfiguration",
80.
81.   "Win32_DMAChannel"                    ,
82.
83.   "Win32_Fan"                           ,
84.
85.   "Win32_FloppyController"              ,
86.
87.   "Win32_FloppyDrive"                   ,
88.
89.   "Win32_HeatPipe"                      ,
90.
91.   "Win32_IDEController"                 ,
92.
93.   "Win32_InfraredDevice"                ,
94.
95.   "Win32_IRQResource"                   ,
96.
97.   "Win32_Keyboard"                      ,
98.
99.   "Win32_MemoryArray"                   ,
100.
101.   "Win32_MemoryDevice"                  ,
102.
103.   "Win32_MotherboardDevice"             ,
104.
105.   "Win32_NetworkAdapter"                ,
106.
107.   "Win32_NetworkAdapterConfiguration"   ,
108.
109.   "Win32_OnBoardDevice"                 ,
110.
111.   "Win32_ParallelPort"                  ,
112.
113.   "Win32_PCMCIAController"              ,
114.
115.   "Win32_PhysicalMemory"                ,
116.
117.   "Win32_PhysicalMemoryArray"           ,
118.
119.   "Win32_PnPEntity"                     ,
120.
121.   "Win32_PointingDevice"                ,
122.
123.   "Win32_PortableBattery"               ,
124.
125.   "Win32_PortConnector"                 ,
126.
127.   "Win32_PortResource"                  ,
128.
129.   "Win32_POTSModem"                     ,
130.
131.   "Win32_PowerManagementEvent"          ,
132.
133.   "Win32_Printer"                       ,
134.
135.   "Win32_PrinterConfiguration"          ,
136.
137.   "Win32_PrintJob"                      ,
138.
139.   "Win32_Processor"                     ,
140.
141.   "Win32_Refrigeration"                 ,
142.
143.   "Win32_SerialPort"                    ,
144.
145.   "Win32_SerialPortConfiguration"       ,
146.
147.   "Win32_SMBIOSMemory"                  ,
148.
149.   "Win32_SoundDevice"                   ,
150.
151.   "Win32_SystemEnclosure"               ,
152.
153.   "Win32_SystemMemoryResource"          ,
154.
155.   "Win32_SystemSlot"                    ,
156.
157.   "Win32_TapeDrive"                     ,
158.
159.   "Win32_TemperatureProbe"              ,
160.
161.   "Win32_UninterruptiblePowerSupply"    ,
162.
163.   "Win32_USBController"                 ,
164.
165.   "Win32_VideoConfiguration"            ,
166.
167.   "Win32_VideoController"               ,
168.
169.   "Win32_VoltageProbe"                  ,

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved