本帖最后由 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的值.
|