U盘自动启动
2025-3-28 乱云飞
#Persistent #SingleInstance ignore ; === 配置部分 === Allowed_USB_IDs := ["EZSOFT", "bakevision"] ; 允许的U盘卷标列表 CheckInterval := 3000 ; 检测间隔(毫秒) TargetExePath := "ezsoft\ez30.exe" ; 目标程序路径 TargetExeName := "ez30.exe" ; 目标进程名(不含路径) ConfigExePath := "ezsoft\虚拟监控.exe" ; 配置程序路径(U盘根目录) DebugMode := false ; 调试模式(true显示提示) ; === 全局变量 === CurrentUSBDrive := "" ; 当前检测到的U盘盘符 ; === 托盘图标设置 === Menu, Tray, NoStandard ; 移除标准菜单项 Menu, Tray, Add, 设置, RunConfig ; 添加设置菜单 Menu, Tray, Add ; 添加分隔线 Menu, Tray, Add, 退出, ExitScript ; 添加自定义退出选项 Menu, Tray, Tip, USB监控程序 ; 设置托盘提示文本 Menu, Tray, Icon ; 显示托盘图标 ; === 主循环:检测U盘 === SetTimer, CheckUSB, %CheckInterval% return CheckUSB: DriveGet, driveList, List, Removable foundValidDrive := false Loop, Parse, driveList { driveLetter := A_LoopField ":\" DriveGet, driveStatus, Status, %driveLetter% if (driveStatus = "Ready") { ; 获取U盘卷标 DriveGet, volumeName, Label, %driveLetter% if (DebugMode) MsgBox, [检测] U盘卷标:%volumeName% ; 检查是否是指定U盘之一 for index, allowedID in Allowed_USB_IDs { if (volumeName = allowedID) { foundValidDrive := true CurrentUSBDrive := driveLetter ; 更新当前U盘盘符 ; 检查目标程序是否已在运行 Process, Exist, %TargetExeName% if (ErrorLevel = 0) ; 未运行 { exePath := driveLetter . TargetExePath if FileExist(exePath) { Run, %exePath% if (DebugMode) MsgBox, [操作] 启动程序:%exePath% } else if (DebugMode) MsgBox, [错误] 未找到程序:%exePath% } else if (DebugMode) MsgBox, [跳过] 程序已在运行(PID:%ErrorLevel%) break ; 找到匹配的卷标后跳出循环 } } } } ; 如果没有检测到有效U盘,清空当前盘符记录 if (!foundValidDrive) CurrentUSBDrive := "" return ; === 运行配置程序 === RunConfig: if (CurrentUSBDrive = "") { MsgBox, 未检测到有效的U盘! return } configExeFullPath := CurrentUSBDrive . ConfigExePath if FileExist(configExeFullPath) { Run, %configExeFullPath% if (DebugMode) MsgBox, [操作] 启动配置程序:%configExeFullPath% } else MsgBox, 未找到配置程序:%configExeFullPath% return ; === 退出脚本函数 === ExitScript: ; 关闭虚拟监控进程 Process, Close, %TargetExeName% if (DebugMode) MsgBox, [操作] 已尝试关闭虚拟监控进程 ; 退出脚本自身 ExitApp return本文链接:http://80c.cc/ez/830.html
发表评论: