找回密码
 加入
搜索
查看: 4944|回复: 7

[系统综合] setupapi.au3 查看USB的使用状态

  [复制链接]
发表于 2010-9-24 11:04:30 | 显示全部楼层 |阅读模式
本帖最后由 wjscxs 于 2010-9-28 14:33 编辑


setupid.au3写的好多,真是难以看懂,看懂了又不理解有些概念.还是求P版指导下如何查看USB的使用状态。如图
如何查看USB连接了那些设备?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-9-24 17:00:10 | 显示全部楼层
啊哈,我也想知道答案,不过你的setupid.au3怎么不放上来....
发表于 2010-9-24 21:43:17 | 显示全部楼层
setupid.au3是什么文件?
发表于 2010-9-24 23:24:09 | 显示全部楼层
setupid.au3是什么文件?
redapple2008 发表于 2010-9-24 21:43

本坛传说中的人物p神写的一个udf...
 楼主| 发表于 2010-9-25 07:41:30 | 显示全部楼层
#include <SetupAPI.au3>
#include<array.au3>
_disp("USB",False,"usb")
Func _disp($HDV,$STATS="",$stringN="")
Local $hDevs, $tDevInfo, $sDeviceID,$aMouse[1][2] = [[0]],$sDescr,$sName,$fResult,$hDevInst,$aChild
$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)
For $i=0 to $aChild[0][0]
        If StringInStr(mouselist(),$aChild[$i][1]) Then
                ExitLoop                
        EndIf
        Next
$sDeviceID = $aMouse[$i][1]
EndIf
_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]]
$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
        Return _ArrayToString($aMouse,"@",1,$aMouse[0][0])
        EndFunc
 楼主| 发表于 2010-9-25 07:50:54 | 显示全部楼层
#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
发表于 2010-9-25 12:59:28 | 显示全部楼层
setupid - -|||| 这是谁写的?

获取USB HUB连接的设备用_CM_Enumerate_Children。
#include <Array.au3>
#include <SetupAPI.au3>

$sDeviceId = "USB\ROOT_HUB\4&1301BE71&0"
$hDevInst = _CM_Locate_DevNode($sDeviceId)
$aAttached = _CM_Enumerate_Children($hDevInst)
_ArrayDisplay($aAttached, "Attached devices")


获取任何设备的子设备,都可以用以上方法。

$aAttached是一维数组,里面包含子设备的Device Instance Id,获取设备的显示名称,调用_CM_Get_Device_Display_Name_Ex。

在写FSeven_v4.7时,查了很多资料想获取每个设备的所需电源是多少毫安,可惜不会。
FSeven_v4.7中有获取HUB端口数量、判断供电方式、判断低速高速的方法,具体看其中的_UsbHubAdvanced和_UsbHubRefreshAttachedDevices函数。

FSeven_v4.7 设备管理器 - http://www.autoitx.com/forum.php ... &highlight=fsev

PS: 把标题更正过来吧,如果你所说的setupid是SetupApi的话。
发表于 2010-9-25 14:17:06 | 显示全部楼层
P版一来!啥事都解决了!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-3 10:37 , Processed in 0.083855 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表