#Include <String.au3>
#include <SetupAPI.au3>
#include<array.au3>
;Opt("MustDeclareVars", 1)
Func _disp($HDV,$STATS="",$stringN="")
Local $hDevs, $tDevInfo, $sDeviceID,$aMouse[1][2] = [[0]],$sDescr,$sName,$fResult,$hDevInst,$aChild,$acompare
$hDevs = _SetupDiGetClassDevs($DIGCF_PRESENT, $HDV)
While _SetupDiEnumDeviceInfo($hDevs, $aMouse[0][0], $tDevInfo)
$aMouse[0][0] += 1
$sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_DEVICEDESC)
$sName = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_FRIENDLYNAME)
If $sName <> "" Then $sDescr = $sName
Redim $aMouse[$aMouse[0][0] + 1][2]
$aMouse[$aMouse[0][0]][0] = $sDescr ; 鼠标描述信息
$aMouse[$aMouse[0][0]][1] = _SetupDiGetDeviceInstanceID($hDevs, $tDevInfo) ; 设备范例ID
WEnd
; 枚举网卡只需把"Mouse"改为"Net",磁盘则对应DiskDrive,显卡对应Display。
_SetupDiDestroyDeviceInfoList($hDevs)
for $i=1 To $aMouse[0][0]
if StringLeft($aMouse[$i][1],3) = $stringN Then; 鼠标设备范例ID。
$hDevInst = _CM_Locate_DevNode($aMouse[$i][1])
$aChild = _CM_Enumerate_Children($hDevInst)
;_ArrayDisplay($aChild)
For $j=0 to $aChild[0]
;MsgBox(16,$aChild[$j],mouselist())
$acompare=_StringBetween($aChild[$j],'\','\')
if $acompare <>1 And $acompare <> 0 Then
;MsgBox(16,"have","\.")
For $k=0 to $acompare[0]
$aChild[$j]=$acompare[$k]
If StringInStr(mouselist(),$aChild[$j]) Then
;MsgBox(1,'j='&$j,"有子进程")
If $STATS=True Then
ContinueLoop 3
EndIf
EndIf
Next
EndIf
Next
MsgBox(16,'i='&$i&"锁定","$sDeviceID = $aMouse[$i][1]")
$sDeviceID = $aMouse[$i][1]
EndIf
If $HDV="mouse" Then
$sDeviceID = $aMouse[$i][1]
ElseIf $HDV="cdrom" Then
$sDeviceID = $aMouse[$i][1]
ElseIF $HDV="NET" Then
$sDeviceID = $aMouse[$i][1]
EndIf
;MsgBox(16,'i='&$i,$sDeviceID)
_SetupDiCreateDeviceDevs($sDeviceID, $hDevs, $tDevInfo)
$fResult = _SetupDiDisableDevice($hDevs, $tDevInfo, $STATS) ; 启用/锁定。
_SetupDiDestroyDeviceInfoList($hDevs) ; 销毁设备信息集。
; _CM_Disable_DevNode / _CM_Enable_DevNode 同样可以实现对硬件的禁用启用操作。
; 但_CM_Enable_DevNode不能启用设备管理器或_SetupDiDisableDevice禁用过的硬件。
Next
;_ArrayDisplay($aMouse)
EndFunc
Func mouselist()
Local $hDevs, $tDevInfo, $aMouse[1][2] = [[0]],$aMouseID="|",$i,$sDescr,$sName
$hDevs = _SetupDiGetClassDevs($DIGCF_PRESENT, "mouse")
While _SetupDiEnumDeviceInfo($hDevs, $aMouse[0][0], $tDevInfo)
$aMouse[0][0] += 1
$sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_DEVICEDESC)
$sName = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_FRIENDLYNAME)
If $sName <> "" Then $sDescr = $sName
Redim $aMouse[$aMouse[0][0] + 1][2]
$aMouse[$aMouse[0][0]][0] = $sDescr ; 鼠标描述信息
$aMouse[$aMouse[0][0]][1] = _SetupDiGetDeviceInstanceID($hDevs, $tDevInfo) ; 设备范例ID
WEnd
for $i=0 to $aMouse[0][0]
$aMouseID=$aMouseID & $aMouse[$i][1] &'|'
Next
Return $aMouseID
EndFunc