找回密码
 加入
搜索
查看: 5764|回复: 5

[系统综合] 关于SetupApi.au3应用的问题--如何获得Bus reported device description的值

[复制链接]
发表于 2010-6-1 09:00:19 | 显示全部楼层 |阅读模式
本帖最后由 kemyliu 于 2010-6-2 16:16 编辑

我下面这段程式的用途是找出USB camera 先卸载driver再重新安装其driver. USB camera的Location 值是:$sLocation = "Port_#0002.Hub_#0005",但是卸载driver这一步不成功,代码如下,望达人赐教!
#include <SetupAPI.au3>
Local $i, $sDeviceId, $hDevInst, $sLocation
        Local $hDevs, $tDevInfo, $Camera[1][2] = [[0]]
        $hDevs = _SetupDiGetClassDevs($DIGCF_PRESENT, "USB") ;judge the device is USB device
        While _SetupDiEnumDeviceInfo($hDevs, $Camera[0][0], $tDevInfo)
                        $Camera[0][0] += 1
                        $sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_DEVICEDESC)
                        $sName = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_FRIENDLYNAME)
                        If $sName <> "" Then $sDescr = $sName
                        Redim $Camera[$Camera[0][0] + 1][2]
                        $Camera[$Camera[0][0]][0] = $sDescr     ;USBCamera
                        $Camera[$Camera[0][0]][1] = _SetupDiGetDeviceInstanceID($hDevs, $tDevInfo) ;Device ID
        WEnd
        _SetupDiDestroyDeviceInfoList($hDevs)
;~     _Arraydisplay($Camera)
        For $i=1 To $Camera[0][0]
                If $Camera[$i][0]=="USB Composite Device" Then
                        ; Device Identifier string.
;~                         $sDeviceId = _CM_Get_Device_Id_By_Name_Ex($Camera[$i][0], 1)
                        ; Handle to device instance.
                        $hDevInst = _CM_Locate_DevNode($Camera[$i][1])
                        $sLocation = _CM_Get_DevNode_Registry_Property($hDevInst, $CM_DRP_LOCATION_INFORMATION)
                        MsgBox(0,"location",$sLocation)
                        If $sLocation = "Port_#0002.Hub_#0005" Then
                                _CM_Uninstall_DevNode($hDevInst)
                                Sleep(3000)
                                _CM_Install_Device_Driver($Camera[$i][1])
                        EndIf
                        
                EndIf
        Next
同时也还有一个问题:如何获得Bus reported device description的值.

本帖子中包含更多资源

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

×
 楼主| 发表于 2010-6-1 15:24:59 | 显示全部楼层
本帖最后由 kemyliu 于 2010-6-1 15:28 编辑

没人帮忙,自己今天发奋努力看了一天pusofalse的<SetupApi.au3>和例子终于搞定了,分享一下结果大家共同学习.
#include <SetupAPI.au3>
Local $i, $sDeviceId, $hDevInst
        Local $hDevs, $tDevInfo, $Camera[1][2] = [[0]]
        $hDevs = _SetupDiGetClassDevs($DIGCF_PRESENT, "USB") ;judge the device is USB device
        While _SetupDiEnumDeviceInfo($hDevs, $Camera[0][0], $tDevInfo)
                        $Camera[0][0] += 1
                        $sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_DEVICEDESC)
                        $sName = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_FRIENDLYNAME)
                        If $sName <> "" Then $sDescr = $sName
                        Redim $Camera[$Camera[0][0] + 1][2]
                        $Camera[$Camera[0][0]][0] = $sDescr     ;USBCamera
                        $Camera[$Camera[0][0]][1] = _SetupDiGetDeviceInstanceID($hDevs, $tDevInfo) ;Device ID
                        If $sDescr=="USB Composite Device" Then
                                $hDevInst = _CM_Locate_DevNode($Camera[$Camera[0][0]][1])
                                $sLocation = _CM_Get_DevNode_Registry_Property($hDevInst, $CM_DRP_LOCATION_INFORMATION)
                                If $sLocation = "Port_#0002.Hub_#0005" Then
                                        _SetupDiRemoveDevice($hDevs, $tDevInfo,True)
                                        Sleep(2000)
                                        _CM_Scan_Device_Changes("")
                        EndIf
                        
                EndIf
        WEnd
        _SetupDiDestroyDeviceInfoList($hDevs)
说真的pusofalse的<SetupApi.au3>真是太博大精深了,继续研究中...
不过这个问题还是无解,望达人指教!
如何获得Bus reported device description的值.
发表于 2010-6-1 16:03:47 | 显示全部楼层
其实你刚发完这贴,我就已经看到了~
我貌似说过,如果你的帖子的标题足够清晰的话,我会尽量帮你解答。
不好意思,你被我华丽地无视了。
 楼主| 发表于 2010-6-2 16:17:05 | 显示全部楼层
版主,我改了,希望帮忙
发表于 2010-6-2 18:01:46 | 显示全部楼层
进来学习一下了多谢。
发表于 2010-6-2 19:42:14 | 显示全部楼层
我不会~呵呵,但以后可能就知道了。
我一直在用XP的系统,没有Bus reported device description这个属性,看了MSDN也没有找到~
你可以试下用for循环的方式枚举一次设备的所有属性,看哪个属性返回的值与上图的一样,那这个就是Bus reported device description了。
具体请看$CM_DRP_*开头的常量。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-4 08:10 , Processed in 0.078372 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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