关于SetupApi.au3应用的问题--如何获得Bus reported device description的值
本帖最后由 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 = []
$hDevs = _SetupDiGetClassDevs($DIGCF_PRESENT, "USB") ;judge the device is USB device
While _SetupDiEnumDeviceInfo($hDevs, $Camera, $tDevInfo)
$Camera += 1
$sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_DEVICEDESC)
$sName = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_FRIENDLYNAME)
If $sName <> "" Then $sDescr = $sName
Redim $Camera[$Camera + 1]
$Camera[$Camera] = $sDescr ;USBCamera
$Camera[$Camera] = _SetupDiGetDeviceInstanceID($hDevs, $tDevInfo) ;Device ID
WEnd
_SetupDiDestroyDeviceInfoList($hDevs)
;~ _Arraydisplay($Camera)
For $i=1 To $Camera
If $Camera[$i]=="USB Composite Device" Then
; Device Identifier string.
;~ $sDeviceId = _CM_Get_Device_Id_By_Name_Ex($Camera[$i], 1)
; Handle to device instance.
$hDevInst = _CM_Locate_DevNode($Camera[$i])
$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])
EndIf
EndIf
Next
同时也还有一个问题:如何获得Bus reported device description的值.
本帖最后由 kemyliu 于 2010-6-1 15:28 编辑
没人帮忙,自己今天发奋努力看了一天pusofalse的<SetupApi.au3>和例子终于搞定了,分享一下结果大家共同学习.#include <SetupAPI.au3>
Local $i, $sDeviceId, $hDevInst
Local $hDevs, $tDevInfo, $Camera = []
$hDevs = _SetupDiGetClassDevs($DIGCF_PRESENT, "USB") ;judge the device is USB device
While _SetupDiEnumDeviceInfo($hDevs, $Camera, $tDevInfo)
$Camera += 1
$sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_DEVICEDESC)
$sName = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_FRIENDLYNAME)
If $sName <> "" Then $sDescr = $sName
Redim $Camera[$Camera + 1]
$Camera[$Camera] = $sDescr ;USBCamera
$Camera[$Camera] = _SetupDiGetDeviceInstanceID($hDevs, $tDevInfo) ;Device ID
If $sDescr=="USB Composite Device" Then
$hDevInst = _CM_Locate_DevNode($Camera[$Camera])
$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的值. 其实你刚发完这贴,我就已经看到了~
我貌似说过,如果你的帖子的标题足够清晰的话,我会尽量帮你解答。
不好意思,你被我华丽地无视了。 版主,我改了,希望帮忙 进来学习一下了多谢。 我不会~呵呵,但以后可能就知道了。
我一直在用XP的系统,没有Bus reported device description这个属性,看了MSDN也没有找到~
你可以试下用for循环的方式枚举一次设备的所有属性,看哪个属性返回的值与上图的一样,那这个就是Bus reported device description了。
具体请看$CM_DRP_*开头的常量。
页:
[1]