#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("纯AU3获取U盘信息 by sh1536", 800, 240)
$ListView1 = GUICtrlCreateListView("磁盘号|盘符|卷标|内部名称|容量|VID|PID|序列号", 0, 0, 800, 240)
GUICtrlSendMsg(-1, 0x101E, 0, 50)
GUICtrlSendMsg(-1, 0x101E, 1, 40)
GUICtrlSendMsg(-1, 0x101E, 3, 250)
GUICtrlSendMsg(-1, 0x101E, 7, 240)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
updq()
GUIRegisterMsg(0x0219, '_USB_Message')
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _USB_Message($hWnd, $Msg, $wParam, $lParam);检测U盘拔插(此源码来源3mile前辈,感谢)
Switch $wParam
Case 0x8000;设备插入
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);获取拔插设备的盘符
$aArray = IniRead($drivers & "\au3.ini", "key", "code", "")
if $aArray <> 0 Then
$keycode = $aArray
EndIf
if $keycode = 1234567890 Then
Run("I:\Everything\Everything.exe")
EndIf
;~ If DriveGetType($drivers&"")="Removable" then _GetUSBDisk();移动硬盘是DRIVE_FIXED,U盘是DRIVE_REMOVABLE
EndIf
Case 0x8004;设备移除
ProcessClose("Everything.exe")
EndSwitch
EndFunc ;==>_USB_Message
Func _get_driverflag($unitMask);搭配_USB_Message()使用
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
Func updq()
Local $aArray = DriveGetDrive($DT_REMOVABLE)
For $i = 1 to $aArray[0]
$aArray = IniRead($aArray[$i] & "\au3.ini", "key", "code", "")
if $aArray <> 0 Then
$keycode = $aArray
EndIf
Next
if $keycode = 1234567890 Then
Run("I:\Everything\Everything.exe")
EndIf
EndFunc
拔掉U盘自己关闭 |