nxbigdaddy 发表于 2013-1-17 15:36:58

win7如何监控 usb

求救,win7下如何健康usb啊?之前的方法在xp下没问题,但是到win7下就不行了。

xiaowo 发表于 2013-1-17 15:51:48

WM_DEVICECHANGE 也不行了吗?

haijie1223 发表于 2013-1-17 17:26:45

循环检测USB~或者注册一个函数检测USB

3mile 发表于 2013-1-17 23:55:04


#include <winapiex.au3>
;Global Const $WM_DEVICECHANGE = 537 ;设备发生改变
Global Const $DBT_DEVICEARRIVAL = 0x8000 ;设备插入
Global Const $DBT_DEVICEREMOVECOMPLETE = 0x8004 ;设备移除

GUIRegisterMsg($WM_DEVICECHANGE, 'My_Message_Test')

GUICreate("Test", 400, 300)
GUISetState()

Do
Until GUIGetMsg() = -3

Func My_Message_Test($hWnd, $Msg, $wParam, $lParam)       
        Switch $wParam
                Case $DBT_DEVICEARRIVAL
                        Local $_DEV_BROADCAST_HDR = DllStructCreate("int dbch_size; int dbch_devicetype; int dbch_reserved;", $lParam)
                        If DllStructGetData($_DEV_BROADCAST_HDR, "dbch_devicetype") = 2 Then
                                Local Const $DEV_BROADCAST_VOLUME = DllStructCreate("int dbcv_size; int dbcv_devicetype; int dbcv_reserved; int dbcv_unitmask; word dbcv_flags", $lParam)
                                Local Const $unitMask = DllStructGetData($DEV_BROADCAST_VOLUME, "dbcv_unitmask")
                                $drivers=get_driverflag($unitMask)
                                $GUID = _WinAPI_GetVolumeNameForVolumeMountPoint($drivers & '\')
                                if DriveGetType($drivers&"\")="Removable" then MsgBox(0, '提示!', '检测到设备插入 - ' & $drivers&@crlf&$GUID&@CRLF)
                        EndIf
                       
                Case $DBT_DEVICEREMOVECOMPLETE
                        MsgBox(0, '提示!', '检测到设备被移除 - ' & $lParam)
        EndSwitch
EndFunc   ;==>My_Message_Test

Func get_driverflag($unitMask)
        Local $Count = 0
        Local $Pom = Round($unitMask / 2)

        While $Pom > 0
                $Pom = BitShift($Pom, 1)
                $Count += 1
        WEnd

        If $Count >= 1 And $Count <= 26 Then
                Return Chr(65 + $Count) & ":"
        Else
                Return '?'
        EndIf
EndFunc   ;==>get_driverflag
页: [1]
查看完整版本: win7如何监控 usb