#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")
GUIRegisterMsg(0x0219, 'Monitor')
Monitor(0, 0, 0, 0)
While 1
Sleep(20)
Local $sLbData = '未登录'
If WinExists("浦发银行网银客户端") Then
$sLbData = "客户端版"
ElseIf StringInStr(WinGetTitle("上海浦东发展银行公司网上银行"), "Internet Explorer") Then
$sLbData = "网页版(IE)"
ElseIf StringInStr(WinGetTitle("上海浦东发展银行公司网上银行"), "用户配置") Then
$sLbData = "网页版(Edge)"
EndIf
If GUICtrlRead($WY_stateLabel) <> $sLbData Then GUICtrlSetData($WY_stateLabel, $sLbData)
WEnd
Func Monitor($hWnd, $uMsg, $wParam, $lParam)
If StringLen(_DetectHardID()) > 4 Then
GUICtrlSetData($U_KEY_stateLabel, "已插入")
Else
GUICtrlSetData($U_KEY_stateLabel, "未插入")
EndIf
Return True
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()
Exit
EndFunc ;==>_Exit