本帖最后由 smooth 于 2022-2-6 20:53 编辑
用DllCallbackRegister注册的回调函数,回调时间设定为250毫秒,关闭脚本时会卡死无法正常退出。同样的功能,用AdlibRegister注册,调用时间一样,则不会卡死,不知道是什么原因导致的。
#include <SetupApi.au3>
Opt("GuionEventmode", 1)
Opt("WinTitleMatchMode", 2)
Local $hGUI = GUICreate("", 300, 300)
GUICtrlCreateLabel("U-KEY状态:", 30, 160, 66, 18)
Local $U_KEY_stateLabel = GUICtrlCreateLabel("", 96, 160, 60, 18)
GUICtrlCreateLabel("网银状态:", 30, 200, 60, 18)
Local $WY_stateLabel = GUICtrlCreateLabel("", 90, 200, 60, 18)
GUISetState()
GUISetOnEvent(-3, "_Exit")
$U_KEY_state = DllCallbackRegister("Monitor", "int", "hwnd;uint;uint;dword");注册一个回调函数,用来监视U-KEY插入和拔出状态和网银登录状态。"Monitor"为函数名,"int"为返回的类型,"hwnd;uint;uint;dword"为函数的参数,即该函数有4个参数,分别为:hwnd、uint、uint、dword。
$U_KEY_stateDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 250, "ptr", DllCallbackGetPtr($U_KEY_state))
While 1
Sleep(10)
WEnd
Func Monitor($hWnd, $uiMsg, $idEvent, $dwTime);回调函数
Local Static $sDevs0 = -100, $sLbData0
Local $sLbData
Local $sDevs = _DetectHardID()
If $idEvent = $U_KEY_stateDLL[0] Then
If $sDevs <> $sDevs0 Then
If $sDevs <> '' Then
GUICtrlSetData($U_KEY_stateLabel, "已插入")
Else
GUICtrlSetData($U_KEY_stateLabel, "未插入")
EndIf
$sDevs0 = $sDevs
EndIf
If WinExists("浦发银行网银客户端") Then
$sLbData = "客户端版"
ElseIf StringInStr(WinGetTitle("上海浦东发展银行公司网上银行"), "Internet Explorer") Then
$sLbData = "网页版(IE)"
ElseIf StringInStr(WinGetTitle("上海浦东发展银行公司网上银行"), "用户配置") Then
$sLbData = "网页版(Edge)"
Else
$sLbData = "未登录"
EndIf
If $sLbData0 <> $sLbData Then
$sLbData0 = $sLbData
GUICtrlSetData($WY_stateLabel, $sLbData0)
EndIf
EndIf
EndFunc ;==>Monitor
Func _DetectHardID();检测U-KEY设备实例ID
Local $hDevs, $tDevInfo, $aMouse[1][2] = [[0]]
$hDevs = _SetupDiGetClassDevs($DIGCF_PRESENT, "CDROM");DiskDrive
While _SetupDiEnumDeviceInfo($hDevs, $aMouse[0][0], $tDevInfo)
$aMouse[0][0] += 1
$sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_DEVICEDESC)
$sName = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, $SPDRP_FRIENDLYNAME)
If $sName <> "" Then $sDescr = $sName
ReDim $aMouse[$aMouse[0][0] + 1][2]
$aMouse[$aMouse[0][0]][0] = $sDescr ; 磁盘描述信息
$aMouse[$aMouse[0][0]][1] = _SetupDiGetDeviceInstanceId($hDevs, $tDevInfo) ; 设备范例ID
WEnd
; 枚举网卡只需把"DiskDrive"改为"Net",鼠标则对应Mouse,光驱则为CDROM,显卡对应Display。
_SetupDiDestroyDeviceInfoList($hDevs)
Local $dFindDevs = ""
For $i = 1 To $aMouse[0][0]
If StringInStr($aMouse[$i][1], "USBSTOR\CDROM&VEN_TENDYRON&PROD_U-DISK&REV_1.10\") Then;
$dFindDevs = $aMouse[$i][1]
ExitLoop
EndIf
Next
Return $dFindDevs;把变量值返回给函数_DetectHardID()
EndFunc ;==>_DetectHardID
Func _Exit()
DllCallbackFree($U_KEY_state)
Exit
EndFunc
|