已经安全弹出的U盘,它的设备错误号为47,表示已标记为“安全删除”但仍没有从系统中物理拔出。设备管理器中提示说“若要让这个设备重新工作,需拔出再重新插入”,其实也不必再次插拔,找到这个U盘的父设备,卸载这个父设备再重新更新一次驱动程序 就好了,U盘又能正常工作了。
#include <SetupAPI.au3>
Local $hDeviceInfoList, $tDeviceInfo, $hDevInst, $iStatus, $hParentDevInst, $hNewDeviceInfoList, $sDeviceID
$hDeviceInfoList = _SetupDiGetClassDevs($DIGCF_PRESENT, "DiskDrive")
For $i = 0 To 4096
If _SetupDiEnumDeviceInfo($hDeviceInfoList, $i, $tDeviceInfo) = 0 Then ExitLoop
$hDevInst = DllStructGetData($tDeviceInfo, "DevInst")
$iStatus = _CM_Get_DevNode_Status($hDevInst)
If (@extended <> 47) Then ContinueLoop
$hParentDevInst = _CM_Get_Parent($hDevInst)
$sDeviceID = _CM_Get_Device_ID($hParentDevInst)
$hNewDeviceInfoList = _SetupDiCreateDeviceInfoList()
_SetupDiOpenDeviceInfo($hNewDeviceInfoList, $sDeviceID, $tDeviceInfo)
_SetupDiRemoveDevice($hNewDeviceInfoList, $tDeviceInfo, 1)
_CM_Scan_Device_Changes("", $CM_REENUMERATE_RETRY_INSTALLATION)
_SetupDiDestroyDeviceInfoList($hDeviceInfoList)
_SetupDiDestroyDeviceInfoList($hNewDeviceInfoList)
Next
MsgBox(48, "OK", "Done.")
|