#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiTreeView.au3>
#include <SetupApi.au3>
$DMGUI = GUICreate("Device Manager", 800, 600)
$DMTree = GUICtrlCreateTreeView(1, 1, 800, 600)
_HardwareScan()
GUISetState()
While 1
If GUIGetMsg() = -3 Then Exit
WEnd
Func _HardwareScan() ;扫描本机硬件信息并将信息添加至 TREE 控件
Global $Hardware[2000][4], $Class[2000][2], $HWNum = 1
_FindDeviceRecur(_CM_Locate_DevNode(""))
ReDim $Hardware[$HWNum][4]
$Hardware[0][0] = $HWNum-1
_ArraySort($Hardware, 0, 1, 0, 1)
_GUICtrlTreeView_DeleteAll($DMTree)
Local $ClassItemString = "", $hItem2, $icon, $v
$hItem = GUICtrlCreateTreeViewItem(@ComputerName, $DMTree) ;计算机名添加进 TREE控件
For $a = 1 To $Hardware[0][0]
$GUID = $Hardware[$a][3]
$GUIDName = $Hardware[$a][1]
If Not StringInStr($ClassItemString, $GUIDName & "|") Then
$hItem2 = GUICtrlCreateTreeViewItem($GUIDName, $hItem) ;大类
$IconString = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class" & $GUID, "IconPath")
If $IconString <> "" Then
$tt = StringSplit($IconString, ",")
If Not @error And $tt[0] = 2 Then
;If $GUID = "{4d36e968-e325-11ce-bfc1-08002be10318}" Or $GUID = "{eec5ad98-8080-425f-922a-dabf3de3f69a}" Then ;显卡及便捷设备图标
; $icon = @ScriptDir & "\ICON" & $GUID & ".ICO"
; $v = 0
;Else
$icon = $tt[1]
$v = $tt[2]
;EndIf
_GUICtrlTreeView_SetIcon($DMTree, $hItem2, $icon, $v)
EndIf
EndIf
$ClassItemString &= $GUIDName & "|"
EndIf
$hItem3 = GUICtrlCreateTreeViewItem($Hardware[$a][0], $hItem2) ;硬件添加进 TREE内的大类,如显卡设备属于 显示适配器 类
_GUICtrlTreeView_SetIcon($DMTree, $hItem3, $icon, $v)
$hItem4 = GUICtrlCreateTreeViewItem("Version: " & $Hardware[$a][2], $hItem3)
_GUICtrlTreeView_SetIcon($DMTree, $hItem4, $icon, $v)
Next
GUICtrlSetState($hItem, $GUI_EXPAND) ;展开父项
EndFunc
Func _FindDeviceRecur($hDevInst) ;找到并将符合条件的设备添加进数组,此函数供 _HardwareScan() 函数调用
$aChild = _CM_Enumerate_Children_Ex($hDevInst, 0)
For $i = 1 To $aChild[0]
$hDevInst = _CM_Locate_DevNode($aChild[$i])
$aChild[$i] = StringUpper($aChild[$i])
$iStatus = _CM_Get_DevNode_Status($hDevInst) ;根据设备号来判断设备是否在 设备管理器 内显示出来 $DN_NO_SHOW_IN_DM
If bitAND($iStatus, $DN_NO_SHOW_IN_DM) Then ContinueLoop
$CLASSGuid = _CM_Get_DevNode_Registry_Property($hDevInst, $CM_DRP_CLASSGUID) ;根据设备ID取得该设备所属的CLASS
If $CLASSGuid = "{8ECC055D-047F-11D1-A537-0000F8753ED1}" Then ContinueLoop ;非即插即用设备 排除
$DEVName = _CM_Get_DevNode_Registry_Property($hDevInst, $CM_DRP_FRIENDLYNAME) ;设备名称
If $DEVName = "" Then $DEVName = _CM_Get_DevNode_Registry_Property($hDevInst, $CM_DRP_DEVICEDESC) ;设备名称
$GetClass = _CM_Get_DevNode_Registry_Property($hDevInst, $CM_DRP_CLASS) ;根据设备ID取得该设备所属的CLASS
$GetService = _CM_Get_DevNode_Registry_Property($hDevInst, $CM_DRP_SERVICE)
$tStatus = _CM_Query_Device_Problem($hDevInst) ;根据设备号返回设备状态代码
$CLASSName = _SetupDiGetClassDescription($CLASSGuid)
$Hardware[$HWNum][1] = _SetupDiGetClassDescription($CLASSGuid) ;将设备所属的 Class 中文名称
$Hardware[$HWNum][0] = $DEVName ;将设备名称 写进数组
$Hardware[$HWNum][2] = _Get_Driver_Version($hDevInst) ;驱动版本
$Hardware[$HWNum][3] = $CLASSGuid ;
$HWNum += 1
_FindDeviceRecur($hDevInst)
Next
EndFunc
Func _Get_Driver_Version($hDevInst)
$ClassGUID = _CM_Get_DevNode_Registry_Property($hDevInst, 10)
If $ClassGUID = "" Then Return "Unknown"
If @OSArch = "X86" Then
$Reg = "HKLM\SYSTEM\ControlSet001\Control\Class"
Else
$Reg = "HKLM64\SYSTEM\ControlSet001\Control\Class"
EndIf
$Version = RegRead($Reg & $ClassGUID, "DriverVersion")
If $Version = "" Then
Return "Unknown"
Else
Return $Version
EndIf
EndFunc