├── Lib ├── JSON.ahk ├── RunAnyCtrl.ico ├── RunAnyCtrlFunc.ahk ├── RunAnyCtrlPlugins.ahk ├── RunAnyCtrlRule.ini ├── rule_common.ahk └── rule_time.ahk ├── README.md ├── RunAnyCtrl.ahk ├── RunAnyCtrl.exe ├── RunAnyCtrl_Update.ahk └── RunAnyCtrl使用说明.png /Lib/JSON.ahk: -------------------------------------------------------------------------------- 1 | class JSON 2 | { 3 | class Load extends JSON.Functor 4 | { 5 | Call(self, text, reviver:="") 6 | { 7 | this.rev := IsObject(reviver) ? reviver : false 8 | this.keys := this.rev ? {} : false 9 | static q := Chr(34) 10 | , json_value := q . "{[01234567890-tfn" 11 | , json_value_or_array_closing := q . "{[]01234567890-tfn" 12 | , object_key_or_object_closing := q . "}" 13 | key := "" 14 | is_key := false 15 | root := {} 16 | stack := [root] 17 | next := json_value 18 | pos := 0 19 | while ((ch := SubStr(text, ++pos, 1)) != "") { 20 | if InStr(" `t`r`n", ch) 21 | continue 22 | if !InStr(next, ch, 1) 23 | this.ParseError(next, text, pos) 24 | holder := stack[1] 25 | is_array := holder.IsArray 26 | if InStr(",:", ch) { 27 | next := (is_key := !is_array && ch == ",") ? q : json_value 28 | } else if InStr("}]", ch) { 29 | ObjRemoveAt(stack, 1) 30 | next := stack[1]==root ? "" : stack[1].IsArray ? ",]" : ",}" 31 | } else { 32 | if InStr("{[", ch) { 33 | static json_array := Func("Array").IsBuiltIn || ![].IsArray ? {IsArray: true} : 0 34 | (ch == "{") 35 | ? ( is_key := true 36 | , value := {} 37 | , next := object_key_or_object_closing ) 38 | : ( value := json_array ? new json_array : [] 39 | , next := json_value_or_array_closing ) 40 | ObjInsertAt(stack, 1, value) 41 | if (this.keys) 42 | this.keys[value] := [] 43 | } else { 44 | if (ch == q) { 45 | i := pos 46 | while (i := InStr(text, q,, i+1)) { 47 | value := StrReplace(SubStr(text, pos+1, i-pos-1), "\\", "\u005c") 48 | static ss_end := A_AhkVersion<"2" ? 0 : -1 49 | if (SubStr(value, ss_end) != "\") 50 | break 51 | } 52 | if (!i) 53 | this.ParseError("'", text, pos) 54 | value := StrReplace(value, "\/", "/") 55 | , value := StrReplace(value, "\" . q, q) 56 | , value := StrReplace(value, "\b", "`b") 57 | , value := StrReplace(value, "\f", "`f") 58 | , value := StrReplace(value, "\n", "`n") 59 | , value := StrReplace(value, "\r", "`r") 60 | , value := StrReplace(value, "\t", "`t") 61 | pos := i 62 | i := 0 63 | while (i := InStr(value, "\",, i+1)) { 64 | if !(SubStr(value, i+1, 1) == "u") 65 | this.ParseError("\", text, pos - StrLen(SubStr(value, i+1))) 66 | uffff := Abs("0x" . SubStr(value, i+2, 4)) 67 | if (A_IsUnicode || uffff < 0x100) 68 | value := SubStr(value, 1, i-1) . Chr(uffff) . SubStr(value, i+6) 69 | } 70 | if (is_key) { 71 | key := value, next := ":" 72 | continue 73 | } 74 | } else { 75 | value := SubStr(text, pos, i := RegExMatch(text, "[\]\},\s]|$",, pos)-pos) 76 | static number := "number" 77 | if value is %number% 78 | value += 0 79 | else if (value == "true" || value == "false") 80 | value := %value% + 0 81 | else if (value == "null") 82 | value := "" 83 | else 84 | this.ParseError(next, text, pos, i) 85 | pos += i-1 86 | } 87 | next := holder==root ? "" : is_array ? ",]" : ",}" 88 | } 89 | is_array? key := ObjPush(holder, value) : holder[key] := value 90 | if (this.keys && this.keys.HasKey(holder)) 91 | this.keys[holder].Push(key) 92 | } 93 | } 94 | return this.rev ? this.Walk(root, "") : root[""] 95 | } 96 | ParseError(expect, text, pos, len:=1) 97 | { 98 | static q := Chr(34) 99 | line := StrSplit(SubStr(text, 1, pos), "`n", "`r").Length() 100 | col := pos - InStr(text, "`n",, -(StrLen(text)-pos+1)) 101 | msg := Format("{1}`n`nLine:`t{2}`nCol:`t{3}`nChar:`t{4}" 102 | , (expect == "") ? "Extra data" 103 | : (expect == "'") ? "Unterminated string starting at" 104 | : (expect == "\") ? "Invalid \escape" 105 | : (expect == ":") ? "Expecting ':' delimiter" 106 | : (expect == q) ? "Expecting object key enclosed in double quotes" 107 | : (expect == q . "}") ? "Expecting object key enclosed in double quotes or object closing '}'" 108 | : (expect == ",}") ? "Expecting ',' delimiter or object closing '}'" 109 | : (expect == ",]") ? "Expecting ',' delimiter or array closing ']'" 110 | : InStr(expect, "]") ? "Expecting JSON value or array closing ']'" 111 | : "Expecting JSON value(string, number, true, false, null, object or array)" 112 | , line, col, pos) 113 | static offset := A_AhkVersion<"2" ? -3 : -4 114 | throw Exception(msg, offset, SubStr(text, pos, len)) 115 | } 116 | Walk(holder, key) 117 | { 118 | value := holder[key] 119 | if IsObject(value) { 120 | for i, k in this.keys[value] { 121 | v := this.Walk.Call(this, value, k) 122 | if (v != JSON.Undefined) 123 | value[k] := v 124 | else 125 | ObjDelete(value, k) 126 | } 127 | } 128 | return this.rev.Call(holder, key, value) 129 | } 130 | } 131 | class Dump extends JSON.Functor 132 | { 133 | Call(self, value, replacer:="", space:="") 134 | { 135 | this.rep := IsObject(replacer) ? replacer : "" 136 | this.gap := "" 137 | if (space) { 138 | static integer := "integer" 139 | if space is %integer% 140 | Loop, % ((n := Abs(space))>10 ? 10 : n) 141 | this.gap .= " " 142 | else 143 | this.gap := SubStr(space, 1, 10) 144 | this.indent := "`n" 145 | } 146 | return this.Str({"": value}, "") 147 | } 148 | Str(holder, key) 149 | { 150 | value := holder[key] 151 | if (this.rep) 152 | value := this.rep.Call(holder, key, ObjHasKey(holder, key) ? value : JSON.Undefined) 153 | if IsObject(value) { 154 | static type := A_AhkVersion<"2" ? "" : Func("Type") 155 | if (type ? type.Call(value) == "Object" : ObjGetCapacity(value) != "") { 156 | if (this.gap) { 157 | stepback := this.indent 158 | this.indent .= this.gap 159 | } 160 | is_array := value.IsArray 161 | if (!is_array) { 162 | for i in value 163 | is_array := i == A_Index 164 | until !is_array 165 | } 166 | str := "" 167 | if (is_array) { 168 | Loop, % value.Length() { 169 | if (this.gap) 170 | str .= this.indent 171 | v := this.Str(value, A_Index) 172 | str .= (v != "") ? v . "," : "null," 173 | } 174 | } else { 175 | colon := this.gap ? ": " : ":" 176 | for k in value { 177 | v := this.Str(value, k) 178 | if (v != "") { 179 | if (this.gap) 180 | str .= this.indent 181 | str .= this.Quote(k) . colon . v . "," 182 | } 183 | } 184 | } 185 | if (str != "") { 186 | str := RTrim(str, ",") 187 | if (this.gap) 188 | str .= stepback 189 | } 190 | if (this.gap) 191 | this.indent := stepback 192 | return is_array ? "[" . str . "]" : "{" . str . "}" 193 | } 194 | } else 195 | return ObjGetCapacity([value], 1)=="" ? value : this.Quote(value) 196 | } 197 | Quote(string) 198 | { 199 | static q := Chr(34) 200 | if (string != "") { 201 | string := StrReplace(string, "\", "\\") 202 | , string := StrReplace(string, q, "\" . q) 203 | , string := StrReplace(string, "`b", "\b") 204 | , string := StrReplace(string, "`f", "\f") 205 | , string := StrReplace(string, "`n", "\n") 206 | , string := StrReplace(string, "`r", "\r") 207 | , string := StrReplace(string, "`t", "\t") 208 | static rx_escapable := A_AhkVersion<"2" ? "O)[^\x20-\x7e]" : "[^\x20-\x7e]" 209 | while RegExMatch(string, rx_escapable, m) 210 | string := StrReplace(string, m.Value, Format("\u{1:04x}", Ord(m.Value))) 211 | } 212 | return q . string . q 213 | } 214 | } 215 | Undefined[] 216 | { 217 | get { 218 | static empty := {}, vt_empty := ComObject(0, &empty, 1) 219 | return vt_empty 220 | } 221 | } 222 | class Functor 223 | { 224 | __Call(method, args*) 225 | { 226 | if IsObject(method) 227 | return (new this).Call(method, args*) 228 | else if (method == "") 229 | return (new this).Call(args*) 230 | } 231 | } 232 | } -------------------------------------------------------------------------------- /Lib/RunAnyCtrl.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hui-Zz/RunAnyCtrl/bbc062af80de12c2d4832a18bdff1e9a06b702db/Lib/RunAnyCtrl.ico -------------------------------------------------------------------------------- /Lib/RunAnyCtrlFunc.ahk: -------------------------------------------------------------------------------- 1 | /* 2 | 【RunAnyCtrl特殊函数调用库】 3 | */ 4 | global RunAnyCtrlFunc_version:="2.5.1" 5 | /* 6 | 【自动识别AHK脚本中的函数 by hui-Zz】(RunAnyCtrl使用中,勿删慎改) 7 | ahkPath AHK脚本路径 8 | return AHK脚本所有函数用|分隔的字符串,没有返回"" 9 | */ 10 | getAhkFuncZz(ahkPath){ 11 | funcName:=funcnameStr:="" 12 | StringReplace, checkPath, ahkPath,`%A_ScriptDir`%, %A_ScriptDir% 13 | if(FileExist(checkPath)){ 14 | funcIndex:=0 15 | getFuncNameReg:="iS)^\t*\s*(?!if)([^\s\.,:=\(]*)\(.*?\)\t*\s*" 16 | getFuncNameReg1:=getFuncNameReg . "\{" 17 | getFuncNameReg2:=getFuncNameReg . "$" 18 | Loop, read, %checkPath% 19 | { 20 | if(RegExMatch(A_LoopReadLine,getFuncNameReg1)){ 21 | funcnameStr.=RegExReplace(A_LoopReadLine,getFuncNameReg1,"$1") . "|" 22 | } 23 | if(funcName && A_Index=funcIndex && RegExMatch(A_LoopReadLine,"^\t*\s*\{\t*\s*$")){ 24 | funcnameStr.=funcName . "|" 25 | } 26 | if(RegExMatch(A_LoopReadLine,getFuncNameReg2)){ 27 | funcName:=RegExReplace(A_LoopReadLine,getFuncNameReg2,"$1") 28 | funcIndex:=A_Index+1 29 | } 30 | } 31 | stringtrimright, funcnameStr, funcnameStr, 1 32 | } 33 | return funcnameStr 34 | } 35 | /* 36 | 【绝对路径转换为相对路径 by hui-Zz】 37 | fPath 被转换的全路径,可带文件名 38 | ahkPath 相对参照的执行脚本完整全路径,带文件名 39 | return -1 路径参数有误 40 | return -2 被转换路径和参照路径不在同一磁盘,不能转换 41 | */ 42 | funcPath2RelativeZz(fPath,ahkPath){ 43 | SplitPath, fPath, fname, fdir, fext, , fdrive 44 | SplitPath, ahkPath, name, dir, ext, , drive 45 | if(!fPath || !ahkPath || !dir || !fdir || !fdrive) 46 | return -1 47 | if(fdrive!=drive){ 48 | return -2 49 | } 50 | ;下级目录直接去掉参照目录路径 51 | if(InStr(fPath,dir)){ 52 | filePath:=StrReplace(fPath,dir) 53 | StringTrimLeft, filePath, filePath, 1 54 | return filePath 55 | } 56 | ;上级目录根据层级递进添加多级前缀..\ 57 | pathList:=StrSplit(dir,"\") 58 | Loop,% pathList.MaxIndex() 59 | { 60 | pathStr:="" 61 | upperStr:="" 62 | ;每次向上递进,找到与启动项相匹配路径段替换成..\ 63 | Loop,% pathList.MaxIndex()-A_Index 64 | { 65 | pathStr.=pathList[A_Index] . "\" 66 | } 67 | StringTrimRight, pathStr, pathStr, 1 68 | if(InStr(fdir,pathStr)){ 69 | Loop,% A_Index 70 | { 71 | upperStr.="..\" 72 | } 73 | StringTrimRight, upperStr, upperStr, 1 74 | filePath:=StrReplace(fPath,pathStr,upperStr) 75 | return filePath 76 | } 77 | } 78 | return false 79 | } 80 | /* 81 | 【相对路径转换为绝对路径 by hui-Zz】 82 | aPath 被转换的相对路径,可带文件名 83 | ahkPath 相对参照的执行脚本完整全路径,带文件名 84 | return -1 路径参数有误 85 | */ 86 | funcPath2AbsoluteZz(aPath,ahkPath){ 87 | SplitPath, aPath, fname, fdir, fext, , fdrive 88 | SplitPath, ahkPath, name, dir, ext, , drive 89 | if(!aPath || !ahkPath) 90 | return -1 91 | ;下级目录直接加上参照目录路径 92 | if(!fdrive && !InStr(aPath,"..")){ 93 | return dir . "\" . aPath 94 | } 95 | pathList:=StrSplit(dir,"\") 96 | ;上级目录根据层级递进添加多级路径 97 | if(InStr(aPath,"..\")=1){ 98 | aPathStr:=RegExReplace(aPath, "\.\.\\", , PointCount) 99 | pathStr:="" 100 | ;每次向上递进,找到添加与启动项相匹配路径段 101 | Loop,% pathList.MaxIndex()-PointCount 102 | { 103 | pathStr.=pathList[A_Index] . "\" 104 | } 105 | filePath:=pathStr . aPathStr 106 | return filePath 107 | } 108 | return false 109 | } 110 | /* 111 | 【返回cmd命令的结果值 @hui-Zz】 112 | */ 113 | cmdReturn(command){ 114 | ; WshShell 对象: http://msdn.microsoft.com/en-us/library/aew9yb99 115 | shell := ComObjCreate("WScript.Shell") 116 | ; 通过 cmd.exe 执行单条命令 117 | exec := shell.Exec(ComSpec " /C " command) 118 | ; 读取并返回命令的输出 119 | return exec.StdOut.ReadAll() 120 | } 121 | /* 122 | 【后台静默运行cmd命令缓存文本取值 @hui-Zz】 123 | */ 124 | cmdSilenceReturn(command){ 125 | CMDReturn:="" 126 | cmdFN:="RunAnyCtrlCMD" 127 | try{ 128 | RunWait,% ComSpec " /C " command " > ""%Temp%\" cmdFN ".log""",, Hide 129 | FileRead, CMDReturn, %A_Temp%\%cmdFN%.log 130 | FileDelete,%A_Temp%\%cmdFN%.log 131 | }catch{} 132 | return CMDReturn 133 | } 134 | /* 135 | 【隐藏运行cmd命令并将结果存入剪贴板后取回 @hui-Zz】 136 | */ 137 | cmdClipReturn(command){ 138 | cmdInfo:="" 139 | Clip_Saved:=ClipboardAll 140 | try{ 141 | Clipboard:="" 142 | Run,% ComSpec " /C " command " | CLIP", , Hide 143 | ClipWait,2 144 | cmdInfo:=Clipboard 145 | }catch{} 146 | Clipboard:=Clip_Saved 147 | return cmdInfo 148 | } 149 | /* 150 | 【StdoutToVar不弹窗不缓存取cmd命令结果】 151 | */ 152 | StdoutToVar_CreateProcess(sCmd, sEncoding:="CP0", sDir:="", ByRef nExitCode:=0) { 153 | DllCall( "CreatePipe", PtrP,hStdOutRd, PtrP,hStdOutWr, Ptr,0, UInt,0 ) 154 | DllCall( "SetHandleInformation", Ptr,hStdOutWr, UInt,1, UInt,1 ) 155 | 156 | VarSetCapacity( pi, (A_PtrSize == 4) ? 16 : 24, 0 ) 157 | siSz := VarSetCapacity( si, (A_PtrSize == 4) ? 68 : 104, 0 ) 158 | NumPut( siSz, si, 0, "UInt" ) 159 | NumPut( 0x100, si, (A_PtrSize == 4) ? 44 : 60, "UInt" ) 160 | NumPut( hStdInRd, si, (A_PtrSize == 4) ? 56 : 80, "Ptr" ) 161 | NumPut( hStdOutWr, si, (A_PtrSize == 4) ? 60 : 88, "Ptr" ) 162 | NumPut( hStdOutWr, si, (A_PtrSize == 4) ? 64 : 96, "Ptr" ) 163 | 164 | If ( !DllCall( "CreateProcess", Ptr,0, Ptr,&sCmd, Ptr,0, Ptr,0, Int,True, UInt,0x08000000 165 | , Ptr,0, Ptr,sDir?&sDir:0, Ptr,&si, Ptr,&pi ) ) 166 | Return "" 167 | , DllCall( "CloseHandle", Ptr,hStdOutWr ) 168 | , DllCall( "CloseHandle", Ptr,hStdOutRd ) 169 | 170 | DllCall( "CloseHandle", Ptr,hStdOutWr ) ; The write pipe must be closed before reading the stdout. 171 | VarSetCapacity(sTemp, 4095) 172 | While ( DllCall( "ReadFile", Ptr,hStdOutRd, Ptr,&sTemp, UInt,4095, PtrP,nSize, Ptr,0 ) ) 173 | sOutput .= StrGet(&sTemp, nSize, sEncoding) 174 | 175 | DllCall( "GetExitCodeProcess", Ptr,NumGet(pi,0), UIntP,nExitCode ) 176 | DllCall( "CloseHandle", Ptr,NumGet(pi,0) ) 177 | DllCall( "CloseHandle", Ptr,NumGet(pi,A_PtrSize) ) 178 | DllCall( "CloseHandle", Ptr,hStdOutRd ) 179 | Return sOutput 180 | } 181 | /* 182 | 通过第三方接口获取IP地址等信息 @hui-Zz 183 | query、country、countryCode、regionName、region、city、lat、lon、timezone、isp 184 | 外网ip、国家、国家代码、地区、地区代码、城市、纬度、经度、时区、运营商 185 | */ 186 | get_ip_api(){ 187 | if(!IsObject(JSON)) 188 | return false 189 | ;~ 测试网络连接 190 | lpszUrl:="http://www.ip-api.com" 191 | network:=DllCall("Wininet.dll\InternetCheckConnection", "Ptr", &lpszUrl, "UInt", 0x1, "UInt", 0x0, "Int") 192 | if(!network) 193 | return false 194 | apiUrl=http://ip-api.com/json 195 | sendStr:=apiUrl 196 | whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") 197 | whr.Open("GET", sendStr) 198 | try { 199 | whr.Send() 200 | } catch { 201 | TrayTip,,验证IP地址异常,可能是网络已断开或接口失效,3,1 202 | } 203 | responseStr:= whr.ResponseText 204 | if(responseStr) 205 | jsonData:=JSON.Load(responseStr) 206 | return jsonData 207 | } -------------------------------------------------------------------------------- /Lib/RunAnyCtrlPlugins.ahk: -------------------------------------------------------------------------------- 1 | #Include *i %A_ScriptDir%\Lib\rule_common.ahk 2 | #Include *i %A_ScriptDir%\Lib\rule_time.ahk -------------------------------------------------------------------------------- /Lib/RunAnyCtrlRule.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hui-Zz/RunAnyCtrl/bbc062af80de12c2d4832a18bdff1e9a06b702db/Lib/RunAnyCtrlRule.ini -------------------------------------------------------------------------------- /Lib/rule_common.ahk: -------------------------------------------------------------------------------- 1 | /* 2 | 【RunAnyCtrl公共规则函数库】 3 | */ 4 | global rule_common_version:="2.5.4" 5 | rule_true(){ 6 | return true 7 | } 8 | rule_false(){ 9 | return false 10 | } 11 | /* 12 | 【判断启动项当前是否已经运行】(RunAnyCtrl使用中,勿删慎改) 13 | runNamePath 进程名或者启动项路径 14 | */ 15 | rule_IsRun(runNamePath){ 16 | runValue:=RegExReplace(runNamePath,"iS)(.*?\.exe)($| .*)","$1") ;去掉参数 17 | SplitPath, runValue, name,, ext ; 获取扩展名 18 | if(ext="ahk"){ 19 | if(InStr(runNamePath,"..\")=1){ 20 | runNamePath:=IsFunc("funcPath2AbsoluteZz") ? Func("funcPath2AbsoluteZz").Call(runNamePath,A_ScriptFullPath) : runNamePath 21 | } 22 | IfWinExist, %runNamePath% ahk_class AutoHotkey 23 | { 24 | return true 25 | } 26 | }else if(name){ 27 | Process,Exist,%name% 28 | if ErrorLevel 29 | return true 30 | } 31 | return false 32 | } 33 | /* 34 | 【判断启动项exe今天是否运行过】 35 | runName 启动项名称+后缀 36 | */ 37 | rule_run_today(runName){ 38 | global last_run_time_List 39 | lastRunTime:="" 40 | if(IsObject(last_run_time_List) && last_run_time_List){ 41 | lastRunTime:=last_run_time_List[runName] 42 | }else{ 43 | cmdResult:=IsFunc("cmdSilenceReturn") ? Func("cmdSilenceReturn").Call("dir %windir%\Prefetch /b/a/o-d |findstr /i """ runName """") : "" 44 | flist:=StrSplit(cmdResult,"`r`n") 45 | if(flist && flist[1]){ 46 | lastRun:=% A_WinDir . "\Prefetch\" . flist[1] 47 | FileGetTime, lastRunTime, %lastRun% 48 | } 49 | } 50 | if(lastRunTime){ 51 | FormatTime, t1, %A_Now%, yyyyMMdd 52 | FormatTime, t2, %lastRunTime%, yyyyMMdd 53 | t1 -= %t2%, Days 54 | return !t1 ? true : false 55 | }else{ 56 | return false 57 | } 58 | } 59 | /* 60 | 【判断启动项文件今天是否运行过】 61 | runName 启动项名称+后缀 62 | */ 63 | rule_run_today_file(runName){ 64 | global last_run_time_List 65 | lastRunTime:="" 66 | if(IsObject(last_run_time_List) && last_run_time_List){ 67 | lastRunTime:=last_run_time_List[runName] 68 | }else{ 69 | cmdResult:=IsFunc("cmdSilenceReturn") ? Func("cmdSilenceReturn").Call("dir %appdata%\Microsoft\Windows\Recent /b/a/o-d |findstr /i """ runName """") : "" 70 | flist:=StrSplit(cmdResult,"`r`n") 71 | if(flist && flist[1]){ 72 | lastRun:=% A_AppData . "\Microsoft\Windows\Recent\" . flist[1] . ".lnk" 73 | FileGetTime, lastRunTime, %lastRun% 74 | } 75 | } 76 | if(lastRunTime){ 77 | FormatTime, t1, %A_Now%, yyyyMMdd 78 | FormatTime, t2, %lastRunTime%, yyyyMMdd 79 | t1 -= %t2%, Days 80 | return !t1 ? true : false 81 | }else{ 82 | return false 83 | } 84 | } 85 | /* 86 | 【验证网络是否连接正常】 87 | lpszUrl 网络测试网址,不传默认用百度做为测试站点 88 | */ 89 | rule_network(lpszUrl="http://www.baidu.com"){ 90 | FLAG_ICC_FORCE_CONNECTION := 0x1 91 | dwReserved := 0x0 92 | return DllCall("Wininet.dll\InternetCheckConnection", "Ptr", &lpszUrl, "UInt", FLAG_ICC_FORCE_CONNECTION, "UInt", dwReserved, "Int") 93 | } 94 | /* 95 | 【验证当前连接的Wifi名称】(闪动命令框) 96 | ssid wifi名称 97 | */ 98 | rule_wifi_twinkle(ssid){ 99 | cmdResult:=IsFunc("cmdReturn") ? Func("cmdReturn").Call("netsh wlan show interface | findstr ""`\=hour){ 32 | return true 33 | } 34 | } 35 | if(operator="<="){ 36 | if(A_Hour<=hour){ 37 | return true 38 | } 39 | } 40 | if(operator=">"){ 41 | if(A_Hour>hour){ 42 | return true 43 | } 44 | } 45 | if(operator="<"){ 46 | if(A_Hour不传默认为当天日期 | 44 | | 验证网络是否连接正常 | 网络测试网址,
不传默认用百度做为测试站点 | | | 45 | | 验证当前连接的Wifi名称
(命令执行,会闪一下命令框) | wifi名称 | | | 46 | | 验证当前连接的Wifi名称
(后台静默写入bat执行后删除) | wifi名称 | | | 47 | | 验证当前电脑名称 | 电脑名 | | | 48 | | 验证当前登录用户名称 | 用户名 | | | 49 | | 验证当前登录用户有管理员权限 | | | | 50 | | 验证当前windows系统版本 | 系统版本号如:WIN_7, WIN_8, WIN_VISTA, WIN_2003, WIN_XP, WIN_2000,
Windows10版本为具体的版本号数字 | | | 51 | | 验证当前当操作系统为64位 | | | | 52 | | 验证当前内网ip地址 | ip(模糊匹配) | | | 53 | | 验证当前外网ip地址 | ip(模糊匹配) | | | 54 | | 验证当前ip地址定位的省市地址 | 城市名、省名,可查看http://www.ip-api.com | | | 55 | | 验证当前网络运营商 | 运营商名,
如中国电信:China Telecom;移动 China Mobile
具体查看http://www.ip-api.com | | | 56 | 57 | --- 58 | 59 | **你的支持是我最大的动力!金额随意** 60 | 61 | **在此特别感谢 AHK-工兵等对RunAnyCtrl的大力支持,欢迎大家多多提出建议!** 62 | 63 | 64 | 65 | ![支付宝](https://raw.githubusercontent.com/hui-Zz/RunAny/master/支持RunAny.jpg) 66 | -------------------------------------------------------------------------------- /RunAnyCtrl.ahk: -------------------------------------------------------------------------------- 1 | /* 2 | ╔══════════════════════════════════════════════════ 3 | ║【RunAnyCtrl】一劳永逸的规则启动控制器 v2.5.6 4 | ║ https://github.com/hui-Zz/RunAnyCtrl 5 | ║ by hui-Zz 建议:hui0.0713@gmail.com 6 | ║ 讨论QQ群:[246308937]、3222783、493194474 7 | ╚══════════════════════════════════════════════════ 8 | */ 9 | #NoEnv ;~不检查空变量为环境变量 10 | #Persistent ;~让脚本持久运行 11 | #WinActivateForce ;~强制激活窗口 12 | #SingleInstance,Force ;~运行替换旧实例 13 | ListLines,Off ;~不显示最近执行的脚本行 14 | CoordMode,Menu ;~相对于整个屏幕 15 | SetBatchLines,-1 ;~脚本全速执行 16 | SetWorkingDir,%A_ScriptDir% ;~脚本当前工作目录 17 | SetTitleMatchMode,2 ;~窗口标题模糊匹配 18 | DetectHiddenWindows,On ;~显示隐藏窗口 19 | global RunAnyCtrl:="RunAnyCtrl" ;名称 20 | global RunAnyCtrl_version:="2.5.6" 21 | global ahkExePath:=Var_Read("ahkExePath",A_AhkPath) ;AutoHotkey.exe路径 22 | global iniFile:=A_ScriptDir "\" RunAnyCtrl ".ini" 23 | global pluginsFile:=A_ScriptDir "\Lib\RunAnyCtrlPlugins.ahk" 24 | global menuItem:="" 25 | global PluginsList:="RunAnyCtrlFunc,JSON,rule_common,rule_time" 26 | global AdminMode:=A_IsAdmin ? "【管理员运行】" : "" 27 | #Include *i %A_ScriptDir%\Lib\JSON.ahk 28 | #Include *i %A_ScriptDir%\Lib\RunAnyCtrlFunc.ahk 29 | Gosub,Var_Set ;~参数初始化 30 | if(!ahkExePath || !FileExist(ahkExePath)){ 31 | try{ 32 | RegRead, regFileExt, HKEY_CLASSES_ROOT, .ahk 33 | RegRead, regFileIcon, HKEY_CLASSES_ROOT, %regFileExt%\DefaultIcon 34 | regFileIconS:=StrSplit(regFileIcon,",") 35 | }catch{} 36 | if(regFileIconS && regFileIconS[1]){ 37 | Reg_Set("ahkExePath",regFileIconS[1]) 38 | ahkExePath:=regFileIconS[1] 39 | }else{ 40 | InputBox, UserInput, 未找到AutoHotkey.exe, 请输入正确的AutoHotkey.exe所在路径 41 | if !ErrorLevel 42 | Reg_Set("ahkExePath",UserInput) 43 | ahkExePath:=UserInput 44 | } 45 | } 46 | if(A_AhkVersion < 1.1.19){ 47 | TrayTip,,由于你的AHK版本没有高于1.1.19,可能会影响到部分功能的使用,3,1 48 | } 49 | if(!A_IsAdmin && AdminRun && !A_IsCompiled) 50 | { 51 | Run *RunAs %ahkExePath% "%A_ScriptFullPath%" 52 | ExitApp 53 | } 54 | gosub,MenuTray 55 | gosub,Run_Item_Read 56 | #Include *i %A_ScriptDir%\Lib\RunAnyCtrlPlugins.ahk 57 | gosub,Rule_Item_Read 58 | Gosub,Rule_Effect 59 | Gosub,AutoRun_Effect 60 | OnExit,ExitSub 61 | ;每月1日检查版本更新 62 | ;if(A_DD=01 || A_DD=15){ 63 | ;Gosub,Github_Update 64 | ;} 65 | return 66 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 67 | ;~;[启动项管理器] 68 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 69 | LV_Show: 70 | gosub,Run_Item_Read 71 | global RunImageListID:=IL_Create(8) 72 | IL_Add(RunImageListID, "shell32.dll", 1) 73 | IL_Add(RunImageListID, "shell32.dll", 3) 74 | IL_Add(RunImageListID, "shell32.dll", 44) 75 | IL_Add(RunImageListID, A_AhkPath, 1) 76 | IL_Add(RunImageListID, A_AhkPath, 2) 77 | IL_Add(RunImageListID, A_AhkPath, 3) 78 | IL_Add(RunImageListID, A_AhkPath, 4) 79 | IL_Add(RunImageListID, A_AhkPath, 5) 80 | global ColumnName:=1 81 | global ColumnType:=2 82 | global ColumnAutoRun:=3 83 | global ColumnHideRun:=4 84 | global ColumnCloseRun:=5 85 | global ColumnRepeatRun:=6 86 | global ColumnMostRun:=7 87 | global ColumnRuleRun:=8 88 | global ColumnRuleLogic:=9 89 | global ColumnRuleNumber:=10 90 | global ColumnRuleTime:=11 91 | global ColumnStatus:=12 92 | global ColumnLastTime:=13 93 | global ColumnPath:=14 94 | Gui,Destroy 95 | Gui,Default 96 | Gui,+Resize 97 | Gui,Font, s10, Microsoft YaHei 98 | Gui,Add, Listview, xm w900 r20 grid AltSubmit vRunAnyLV glistview, 启动项名|类型|自启|隐藏|自关|不重复|最多|规则|匹配|循环|间隔|状态|最后运行时间|路径 99 | LV_SetImageList(RunImageListID) 100 | ;~;[读取启动项内容写入列表] 101 | GuiControl, -Redraw, RunAnyLV 102 | For runn, runv in run_item_List 103 | { 104 | runStatus:=Check_IsRun(runv) ? "启动" : "" 105 | runValue:=RegExReplace(runv,"iS)(.*?\.exe)($| .*)","$1") ;去掉参数 106 | SplitPath, runValue,,, FileExt ; 获取文件扩展名. 107 | runType:=FileExt ? FileExt : RegExMatch(runv,"iS)([\w-]+://?|www[.]).*") ? "网址" : "未知" 108 | LV_Add(runType="网址" ? "Icon3" : LVRunIcon(runValue,FileExt), runn, runType, auto_run_item_List[runn] ? "是" : "", hide_run_item_List[runn] ? "是" : "", close_run_item_List[runn] ? "是" : "", repeat_run_item_List[runn] ? "是" : "", most_run_item_List[runn], rule_run_item_List[runn] ? "是" : "", rule_run_item_List[runn] ? rule_logic_item_List[runn] ? "与" : "或" : "", rule_number_item_List[runn], rule_time_item_List[runn], runStatus, last_run_time_List[runn], runv) 109 | } 110 | GuiControl, +Redraw, RunAnyLV 111 | LVMenu("LVMenu") 112 | LVMenu("ahkGuiMenu") 113 | Gui, Menu, ahkGuiMenu 114 | LVModifyCol(38,ColumnAutoRun,ColumnHideRun,ColumnCloseRun,ColumnRepeatRun,ColumnRuleRun,ColumnRuleLogic) ; 根据内容自动调整每列的大小. 115 | Gui,Show, , %RunAnyCtrl% 启动控制器 by hui-Zz 2018 %RunAnyCtrl_version% %AdminMode% 116 | return 117 | 118 | LVMenu(addMenu){ 119 | flag:=addMenu="ahkGuiMenu" ? true : false 120 | Menu, %addMenu%, Add,% flag ? "启动" : "启动`tF1", LVRun 121 | Menu, %addMenu%, Icon,% flag ? "启动" : "启动`tF1", %ahkExePath%,2 122 | Menu, %addMenu%, Add,% flag ? "配置" : "配置`tF2", LVConfig 123 | Menu, %addMenu%, Icon,% flag ? "配置" : "配置`tF2", SHELL32.dll,134 124 | Menu, %addMenu%, Add,% flag ? "新建" : "新建`tF3", LVAdd 125 | Menu, %addMenu%, Icon,% flag ? "新建" : "新建`tF3", SHELL32.dll,194 126 | Menu, %addMenu%, Add,% flag ? "挂起" : "挂起`tF4", LVSuspend 127 | Menu, %addMenu%, Icon,% flag ? "挂起" : "挂起`tF4", %ahkExePath%,3 128 | Menu, %addMenu%, Add,% flag ? "暂停" : "暂停`tF5", LVPause 129 | Menu, %addMenu%, Icon,% flag ? "暂停" : "暂停`tF5", %ahkExePath%,4 130 | Menu, %addMenu%, Add,% flag ? "关闭" : "关闭`tF6", LVClose 131 | Menu, %addMenu%, Icon,% flag ? "关闭" : "关闭`tF6", SHELL32.dll,28 132 | Menu, %addMenu%, Add,% flag ? "编辑" : "编辑`tF7", LVEdit 133 | Menu, %addMenu%, Icon,% flag ? "编辑" : "编辑`tF7", SHELL32.dll,2 134 | Menu, %addMenu%, Add,% flag ? "删除" : "删除`tDel", LVDel 135 | Menu, %addMenu%, Icon,% flag ? "删除" : "删除`tDel", SHELL32.dll,132 136 | Menu, %addMenu%, Add,% flag ? "导入" : "导入`tF8", LVImport 137 | Menu, %addMenu%, Icon,% flag ? "导入" : "导入`tF8", SHELL32.dll,46 138 | Menu, %addMenu%, Add,% flag ? "设置" : "设置`tF9", LVSet 139 | Menu, %addMenu%, Icon,% flag ? "设置" : "设置`tF9", SHELL32.dll,22 140 | Menu, %addMenu%, Add,% flag ? "规则" : "规则`tF10", LVRule 141 | Menu, %addMenu%, Icon,% flag ? "规则" : "规则`tF10", SHELL32.dll,166 142 | } 143 | LVRunIcon(FileName,FileExt){ 144 | if(FileName!="" && !InStr(FileName,"\")){ 145 | if(FileExist(A_WinDir "\" FileName)) 146 | FileName=%A_WinDir%\%FileName% 147 | if(FileExist(A_WinDir "\system32\" FileName)) 148 | FileName=%A_WinDir%\system32\%FileName% 149 | } 150 | ; 计算 SHFILEINFO 结构需要的缓存大小. 151 | sfi_size := A_PtrSize + 8 + (A_IsUnicode ? 680 : 340) 152 | VarSetCapacity(sfi, sfi_size) 153 | ;【下面开始处理未知的项目图标】 154 | if FileExt in EXE,ICO,ANI,CUR 155 | { 156 | ExtID := FileExt ; 特殊 ID 作为占位符. 157 | IconNumber = 0 ; 进行标记这样每种类型就含有唯一的图标. 158 | } 159 | else ; 其他的扩展名/文件类型, 计算它们的唯一 ID. 160 | { 161 | ExtID = 0 ; 进行初始化来处理比其他更短的扩展名. 162 | Loop 7 ; 限制扩展名为 7 个字符, 这样之后计算的结果才能存放到 64 位值. 163 | { 164 | StringMid, ExtChar, FileExt, A_Index, 1 165 | if not ExtChar ; 没有更多字符了. 166 | break 167 | ; 把每个字符与不同的位位置进行运算来得到唯一 ID: 168 | ExtID := ExtID | (Asc(ExtChar) << (8 * (A_Index - 1))) 169 | } 170 | ; 检查此文件扩展名的图标是否已经在图像列表中. 如果是, 171 | ; 可以避免多次调用并极大提高性能, 172 | ; 尤其对于包含数以百计文件的文件夹而言: 173 | if(ExtID>0) 174 | IconNumber := IconArray%ExtID% 175 | noEXE:=true 176 | } 177 | if not IconNumber ; 此扩展名还没有相应的图标, 所以进行加载. 178 | { 179 | ; 获取与此文件扩展名关联的高质量小图标: 180 | if not DllCall("Shell32\SHGetFileInfo" . (A_IsUnicode ? "W":"A"), "str", FileName 181 | , "uint", 0, "ptr", &sfi, "uint", sfi_size, "uint", 0x101) ; 0x101 为 SHGFI_ICON+SHGFI_SMALLICON 182 | { 183 | IconNumber = 2 ; 显示默认应用图标. 184 | if(noEXE) 185 | IconNumber = 1 186 | } 187 | else ; 成功加载图标. 188 | { 189 | ; 从结构中提取 hIcon 成员: 190 | hIcon := NumGet(sfi, 0) 191 | ; 直接添加 HICON 到小图标和大图标列表. 192 | ; 下面加上 1 来把返回的索引从基于零转换到基于一: 193 | IconNumber := DllCall("ImageList_ReplaceIcon", "ptr", RunImageListID, "int", -1, "ptr", hIcon) + 1 194 | ; 现在已经把它复制到图像列表, 所以应销毁原来的: 195 | DllCall("DestroyIcon", "ptr", hIcon) 196 | ; 缓存图标来节省内存并提升加载性能: 197 | if(ExtID>0) 198 | IconArray%ExtID% := IconNumber 199 | } 200 | } 201 | return "Icon" . IconNumber 202 | } 203 | LVRun: 204 | menuItem:="启动" 205 | gosub,LVApply 206 | return 207 | LVEdit: 208 | menuItem:="编辑" 209 | gosub,LVApply 210 | return 211 | LVSuspend: 212 | menuItem:="挂起" 213 | gosub,LVApply 214 | return 215 | LVPause: 216 | menuItem:="暂停" 217 | gosub,LVApply 218 | return 219 | LVClose: 220 | menuItem:="关闭" 221 | gosub,LVApply 222 | return 223 | LVDel: 224 | menuItem:="删除" 225 | gosub,LVApply 226 | return 227 | LVAdd: 228 | menuItem:="新建" 229 | gosub,GuiConfig 230 | return 231 | LVConfig: 232 | menuItem:="配置" 233 | gosub,GuiConfig 234 | return 235 | LVApply: 236 | Row:=LV_GetNext(0, "F") 237 | RowNumber:=0 238 | if(Row && menuItem="删除"){ 239 | MsgBox,35,确认删除?(Esc取消),确定删除选中的启动项和其中的规则项?(不会删除文件) 240 | DelRowList:="" 241 | } 242 | Loop 243 | { 244 | RowNumber := LV_GetNext(RowNumber) ; 在前一次找到的位置后继续搜索. 245 | if not RowNumber ; 上面返回零, 所以选择的行已经都找到了. 246 | break 247 | LV_GetText(FileName, RowNumber, ColumnName) 248 | LV_GetText(FileHideRun, RowNumber, ColumnHideRun) 249 | LV_GetText(FileStatus, RowNumber, ColumnStatus) 250 | LV_GetText(FilePath, RowNumber, ColumnPath) 251 | if(menuItem="启动"){ 252 | try{ 253 | if(InStr(FilePath,"..\")=1){ 254 | FilePath:=IsFunc("funcPath2AbsoluteZz") ? Func("funcPath2AbsoluteZz").Call(FilePath,A_ScriptFullPath) : FilePath 255 | } 256 | runValue:=RegExReplace(FilePath,"iS)(.*?\.exe)($| .*)","$1") ;去掉参数 257 | SplitPath, runValue, , dir, ext 258 | if(dir && FileExist(dir)){ 259 | SetWorkingDir,%dir% 260 | } 261 | if(FileHideRun="是"){ 262 | Run,%FilePath%,, hide 263 | }else{ 264 | Run,%FilePath% 265 | } 266 | LV_Modify(RowNumber, "", , , , , , , , , , , , "启动", A_Now) 267 | IniWrite, %A_Now%, %iniFileLastRunTime%, last_run_time, %FileName% 268 | } finally { 269 | SetWorkingDir,%A_ScriptDir% 270 | } 271 | }else if(menuItem="编辑"){ 272 | ;~ PostMessage, 0x111, 65401,,, %FilePath% ahk_class AutoHotkey 273 | if(A_AhkPath){ 274 | Run,edit "%FilePath%" 275 | }else{ 276 | Run,notepad.exe "%FilePath%" 277 | } 278 | }else if(menuItem="挂起"){ 279 | PostMessage, 0x111, 65404,,, %FilePath% ahk_class AutoHotkey 280 | LVStatusChange(RowNumber,FileStatus,"挂起") 281 | }else if(menuItem="暂停"){ 282 | PostMessage, 0x111, 65403,,, %FilePath% ahk_class AutoHotkey 283 | LVStatusChange(RowNumber,FileStatus,"暂停") 284 | }else if(menuItem="关闭"){ 285 | runValue:=RegExReplace(FilePath,"iS)(.*?\.exe)($| .*)","$1") ;去掉参数 286 | SplitPath, runValue, name,, ext ; 获取扩展名 287 | if(ext="ahk"){ 288 | if(InStr(FilePath,"..\")=1){ 289 | FilePath:=IsFunc("funcPath2AbsoluteZz") ? Func("funcPath2AbsoluteZz").Call(FilePath,A_ScriptFullPath) : FilePath 290 | } 291 | PostMessage, 0x111, 65405,,, %FilePath% ahk_class AutoHotkey 292 | runStatus:="" 293 | }else if(name){ 294 | Process,Close,%name% 295 | if ErrorLevel 296 | runStatus:="" 297 | } 298 | LV_Modify(RowNumber, "", , , , , , , , , , , , runStatus) 299 | }else if(menuItem="删除"){ 300 | IfMsgBox Yes 301 | { 302 | DelRowList := RowNumber . ":" . DelRowList 303 | For ki, kv in KeyList 304 | { 305 | if(kv="rule_item" || kv="func_item") 306 | continue 307 | IniDelete, %iniFile%, %kv%, %FileName% 308 | } 309 | IniDelete, %iniFile%, %FileName% 310 | gosub,Run_Item_Read 311 | } 312 | } 313 | } 314 | if(menuItem="删除"){ 315 | IfMsgBox Yes 316 | { 317 | stringtrimright, DelRowList, DelRowList, 1 318 | loop, parse, DelRowList, : 319 | LV_Delete(A_loopfield) 320 | } 321 | } 322 | return 323 | 324 | GuiConfig: 325 | gosub,Rule_Item_Read 326 | FileName:=FileAutoRun:=FileHideRun:=FileCloseRun:=FileRepeatRun:=FileMostRun:=FileRuleRun:=FileRuleNumber:=FileRuleTime:=FilePath:="" 327 | FileRuleLogic1:=1 328 | if(menuItem="配置"){ 329 | RunRowNumber := LV_GetNext(0, "F") 330 | if not RunRowNumber 331 | return 332 | LV_GetText(FileName, RunRowNumber, ColumnName) 333 | LV_GetText(FileAutoRun, RunRowNumber, ColumnAutoRun) 334 | LV_GetText(FileHideRun, RunRowNumber, ColumnHideRun) 335 | LV_GetText(FileCloseRun, RunRowNumber, ColumnCloseRun) 336 | LV_GetText(FileRepeatRun, RunRowNumber, ColumnRepeatRun) 337 | LV_GetText(FileMostRun, RunRowNumber, ColumnMostRun) 338 | LV_GetText(FileRuleRun, RunRowNumber, ColumnRuleRun) 339 | LV_GetText(FileRuleNumber, RunRowNumber, ColumnRuleNumber) 340 | LV_GetText(FileRuleTime, RunRowNumber, ColumnRuleTime) 341 | LV_GetText(FilePath, RunRowNumber, ColumnPath) 342 | FileRuleLogic1:=rule_logic_item_List[FileName] 343 | FileDelayRun:=delay_run_item_List[FileName] 344 | } 345 | FileRuleLogic2:=FileRuleLogic1 ? 0 : 1 346 | FileAutoRun:=FileAutoRun="是" ? 1 : 0 347 | FileHideRun:=FileHideRun="是" ? 1 : 0 348 | FileCloseRun:=FileCloseRun="是" ? 1 : 0 349 | FileRepeatRun:=FileRepeatRun="是" ? 1 : 0 350 | FileRuleRun:=FileRuleRun="是" ? 1 : 0 351 | Gui,2:Destroy 352 | Gui,2:Default 353 | Gui,2:Font,,Microsoft YaHei 354 | Gui,2:Margin,20,20 355 | Gui,2:Add, GroupBox,xm y+10 w500 h175,启动项设置 356 | Gui,2:Add, Text, xm+10 y35 w60, 启动项名: 357 | Gui,2:Add, Edit, x+5 yp-3 w400 vvFileName, %FileName% 358 | Gui,2:Add, Button, xm+5 yp+35 w60 GSetFilePath,启动路径 359 | if(IsFunc("funcPath2RelativeZz")){ 360 | Gui,2:Add, Button, xm+5 y+2 w60 GSetFileRelativePath,相对路径 361 | Gui,2:Add, Edit, x+10 yp-30 w400 r3 vvFilePath, %FilePath% 362 | }else{ 363 | Gui,2:Add, Edit, x+10 yp w400 r3 vvFilePath, %FilePath% 364 | } 365 | Gui,2:Add, CheckBox, xm+10 y+5 Checked%FileAutoRun% vvFileAutoRun, 自动启动 366 | Gui,2:Add, CheckBox, x+15 yp Checked%FileHideRun% vvFileHideRun, 隐藏启动 367 | Gui,2:Add, CheckBox, x+10 yp Checked%FileCloseRun% vvFileCloseRun, 随RunAnyCtrl自动关闭 368 | Gui,2:Add, Text, xm+10 y+10 w75, 最多启动次数: 369 | Gui,2:Add, Edit, x+2 yp-3 Number w50 h20 vvFileMostRun, %FileMostRun% 370 | Gui,2:Add, Text, x+10 yp+3 w85, 延迟时间(毫秒): 371 | Gui,2:Add, Edit, x+2 yp-3 Number w90 h20 vvFileDelayRun, %FileDelayRun% 372 | Gui,2:Add, CheckBox, x+20 yp+3 Checked%FileRepeatRun% vvFileRepeatRun, 不重复启动 373 | if(!IsFunc("rule_IsRun")){ 374 | Gui,2:Add, Text, x+2 yp CRed w50, (不可用) 375 | } 376 | Gui,2:Add, GroupBox,xm y+15 w500 h350,规则项设置 377 | Gui,2:Add, CheckBox, xm+10 yp+25 w130 Checked%FileRuleRun% vvFileRuleRun, 使用规则自动启动 378 | Gui,2:Add, Radio, x+20 yp Checked%FileRuleLogic1% vvFileRuleLogic1, 与(全部匹配)(&A) 379 | Gui,2:Add, Radio, x+5 yp Checked%FileRuleLogic2% vvFileRuleLogic2, 或(部分匹配)(&O) 380 | Gui,2:Add, Text, xm+10 y+10 w100, 规则循环最大次数: 381 | Gui,2:Add, Edit, x+2 yp-3 Number w50 h20 vvFileRuleNumber, %FileRuleNumber% 382 | Gui,2:Add, Text, x+20 yp+3 w110, 循环间隔时间(毫秒): 383 | Gui,2:Add, Edit, x+2 yp-3 Number w100 h20 vvFileRuleTime, %FileRuleTime% 384 | Gui,2:Add, Button, xm+10 y+15 w70 GLVFuncAdd, 增加规则 385 | Gui,2:Add, Button, x+10 yp w70 GLVFuncEdit, 修改规则 386 | Gui,2:Add, Button, x+10 yp w70 GLVFuncRemove, 减少规则 387 | Gui,2:Font, s10, Microsoft YaHei 388 | Gui,2:Add, Listview, xm+10 y+10 w480 r10 grid AltSubmit C808000 vFuncLV glistfunc, 规则名|中断|条件|自定义条件值 389 | ;[读取启动项设置的规则内容写入列表] 390 | GuiControl, 2:-Redraw, FuncLV 391 | For k, v in runruleitemList[FileName] 392 | { 393 | LV_Add("", v["ruleName"], v["ruleBreak"] ? "*" : "", v["ruleLogic"] ? "相等" : "不相等", v["ruleParamStr"]) 394 | } 395 | LV_ModifyCol(1) 396 | LV_ModifyCol(2) 397 | LV_ModifyCol(3) 398 | GuiControl, 2:+Redraw, FuncLV 399 | Gui,2:Add,Button,Default xm+150 y+15 w75 GLVSave,保存(&Y) 400 | Gui,2:Add,Button,x+20 w75 GLVCancel,取消(&C) 401 | Gui,2:Show, , %RunAnyCtrl% 启动项规则 - %menuItem% 402 | return 403 | 404 | LVSave: 405 | Gui,2:Submit, NoHide 406 | if(!vFileName || !vFilePath){ 407 | ToolTip, 请填入启动项名和启动路径,195,35 408 | SetTimer,RemoveToolTip,3000 409 | return 410 | } 411 | if(FileName!=vFileName && run_item_List[vFileName]){ 412 | ToolTip, 已存在相同的启动项名,请修改,195,35 413 | SetTimer,RemoveToolTip,3000 414 | return 415 | } 416 | if(Instr(vFileName, A_SPACE)){ 417 | StringReplace, vFileName, vFileName, %A_SPACE%, _, All 418 | GuiControl, 2:, vFileName, %vFileName% 419 | ToolTip, 启动项名不能带有空格,请用_代替,195,35 420 | SetTimer,RemoveToolTip,3000 421 | return 422 | } 423 | if(Instr(vFileName, A_Tab)){ 424 | StringReplace, vFileName, vFileName, %A_Tab%, _, All 425 | GuiControl, 2:, vFileName, %vFileName% 426 | ToolTip, 启动项名不能带有制表符,请用_代替,195,35 427 | SetTimer,RemoveToolTip,3000 428 | return 429 | } 430 | ;中文、数字、字母、下划线正则校验,根据Unicode字符属性Han来判断中文,RunAnyCtrl.ahk编码不能为ANSI 431 | if(!RegExMatch(vFileName,"^[\p{Han}A-Za-z0-9_]+$")){ 432 | ToolTip, 启动项名只能为中文、数字、字母、下划线,195,35 433 | SetTimer,RemoveToolTip,5000 434 | return 435 | } 436 | For ki, kv in KeyList 437 | { 438 | if(vFileName=kv){ 439 | ToolTip, 启动项名不能与RunAnyCtrl内置配置重名,请修改,195,35 440 | SetTimer,RemoveToolTip,5000 441 | return 442 | } 443 | } 444 | ;~ 先删除启动项原有规则项 445 | IniDelete, %iniFile%, %FileName% 446 | ruleContent:="" 447 | Loop % LV_GetCount() 448 | { 449 | LV_GetText(RuleName, A_Index, 1) 450 | LV_GetText(FuncBreak, A_Index, 2) 451 | LV_GetText(FuncBoolean, A_Index, 3) 452 | LV_GetText(FuncValue, A_Index, 4) 453 | FuncBoolean:=FuncBoolean="相等" ? 1 : 0 454 | ruleContent.=RuleName . "|" . FuncBreak . FuncBoolean . "|" . FuncValue . "`n" 455 | } 456 | if(ruleContent){ 457 | stringtrimright, ruleContent, ruleContent, 1 458 | IniWrite, %ruleContent%, %iniFile%, %vFileName% 459 | } 460 | ;[写入配置文件] 461 | Gui,1:Default 462 | vFileRuleLogic:=vFileRuleLogic1 ? 1 : 0 463 | runValue:=RegExReplace(vFilePath,"iS)(.*?\.exe)($| .*)","$1") ;去掉参数 464 | SplitPath, runValue,,, FileExt ; 获取文件扩展名. 465 | runType:=FileExt ? FileExt : RegExMatch(vFilePath,"iS)([\w-]+://?|www[.]).*") ? "网址" : "未知" 466 | if(menuItem="新建"){ 467 | LV_Add("",vFileName,runType,vFileAutoRun ? "是" : "",vFileHideRun ? "是" : "",vFileCloseRun ? "是" : "",vFileRepeatRun ? "是" : "",vFileMostRun,vFileRuleRun ? "是" : "",vFileRuleRun ? vFileRuleLogic ? "与" : "或" : "",vFileRuleNumber,vFileRuleTime,"",,vFilePath) 468 | }else{ 469 | ;~ 删除原有启动项其他配置,不包含规则项 470 | For ki, kv in KeyList 471 | { 472 | if((kv="rule_item" || kv="func_item") || (vFileName=FileName && kv="run_item")) 473 | continue 474 | IniDelete, %iniFile%, %kv%, %FileName% 475 | } 476 | LV_Modify(RunRowNumber,"",vFileName,runType,vFileAutoRun ? "是" : "",vFileHideRun ? "是" : "",vFileCloseRun ? "是" : "",vFileRepeatRun ? "是" : "",vFileMostRun,vFileRuleRun ? "是" : "",vFileRuleRun ? vFileRuleLogic ? "与" : "或" : "",vFileRuleNumber,vFileRuleTime,,,vFilePath) 477 | } 478 | Gui,2:Destroy 479 | GuiControl, 1:+Redraw, RunAnyLV 480 | IniWrite, %vFilePath%, %iniFile%, run_item, %vFileName% 481 | if(vFileAutoRun) 482 | IniWrite, %vFileAutoRun%, %iniFile%, auto_run_item, %vFileName% 483 | if(vFileHideRun) 484 | IniWrite, %vFileHideRun%, %iniFile%, hide_run_item, %vFileName% 485 | if(vFileCloseRun) 486 | IniWrite, %vFileCloseRun%, %iniFile%, close_run_item, %vFileName% 487 | if(vFileRepeatRun) 488 | IniWrite, %vFileRepeatRun%, %iniFile%, repeat_run_item, %vFileName% 489 | if(vFileMostRun) 490 | IniWrite, %vFileMostRun%, %iniFile%, most_run_item, %vFileName% 491 | if(vFileDelayRun) 492 | IniWrite, %vFileDelayRun%, %iniFile%, delay_run_item, %vFileName% 493 | if(vFileRuleRun) 494 | IniWrite, %vFileRuleRun%, %iniFile%, rule_run_item, %vFileName% 495 | if(vFileRuleRun && vFileRuleLogic) 496 | IniWrite, %vFileRuleLogic%, %iniFile%, rule_logic_item, %vFileName% 497 | if(vFileRuleNumber) 498 | IniWrite, %vFileRuleNumber%, %iniFile%, rule_number_item, %vFileName% 499 | if(vFileRuleTime) 500 | IniWrite, %vFileRuleTime%, %iniFile%, rule_time_item, %vFileName% 501 | gosub,Run_Item_Read 502 | return 503 | LVImport: 504 | FileSelectFile, selectName, M35, , 选择多项要导入的AHK(EXE), (*.ahk;*.exe) 505 | Loop,parse,selectName,`n 506 | { 507 | if(A_Index=1){ 508 | dir:=A_LoopField 509 | }else{ 510 | fullPath:=dir "\" A_LoopField 511 | SplitPath, fullPath, , , ext, name_no_ext 512 | if(run_item_List[name_no_ext]){ 513 | TrayTip,,导入项中有已存在的相同文件名启动项,不会导入,3,1 514 | continue 515 | } 516 | LV_Add("", name_no_ext, ext, "", "", "", "", , "", "", , ,"", , fullPath) 517 | IniWrite, %fullPath%, %iniFile%, run_item, %name_no_ext% 518 | } 519 | } 520 | LVModifyCol(38,ColumnAutoRun,ColumnHideRun,ColumnCloseRun,ColumnRepeatRun,ColumnRuleRun,ColumnRuleLogic) ; 根据内容自动调整每列的大小. 521 | return 522 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 523 | ;~;[规则函数配置] 524 | LVFuncAdd: 525 | menuFuncItem:="新建规则函数" 526 | RuleName:=FuncBoolean:=FuncValue:="" 527 | FuncBreak:=0 528 | FuncBoolean1:=1 529 | RuleNameChoose:=1 530 | gosub,LVFuncConfig 531 | return 532 | LVFuncEdit: 533 | menuFuncItem:="修改规则函数" 534 | RowNumber:=LV_GetNext(0, "F") 535 | if not RowNumber 536 | return 537 | LV_GetText(RuleName, RowNumber, 1) 538 | LV_GetText(FuncBreak, RowNumber, 2) 539 | LV_GetText(FuncBoolean, RowNumber, 3) 540 | LV_GetText(FuncValue, RowNumber, 4) 541 | FuncBoolean1:=FuncBoolean="相等" ? 1 : 0 542 | FuncBreak:=FuncBreak ? 1 : 0 543 | RuleNameChoose:=1 544 | loop, parse, rulenameStr, | 545 | { 546 | if(RuleName=A_LoopField){ 547 | RuleNameChoose:=A_Index 548 | break 549 | } 550 | } 551 | ruleParamContent:=ruleParamTen:="" 552 | Loop, parse, FuncValue, | 553 | { 554 | if(A_Index>0 && A_Index<10){ 555 | ruleParamContent.=A_LoopField . "`n" 556 | continue 557 | } 558 | if(A_Index>=10) 559 | ruleParamTen.=A_LoopField . "|" 560 | } 561 | ;第十个参数及以上分隔参数,都归为第十参数 562 | if(ruleParamTen){ 563 | stringtrimright, ruleParamTen, ruleParamTen, 1 564 | ruleParamContent.=ruleParamTen 565 | }else{ 566 | stringtrimright, ruleParamContent, ruleParamContent, 1 567 | } 568 | FuncValue:=ruleParamContent 569 | gosub,LVFuncConfig 570 | return 571 | LVFuncConfig: 572 | FuncBoolean2:=FuncBoolean1 ? 0 : 1 573 | Gui,F:Destroy 574 | Gui,F:Font,,Microsoft YaHei 575 | Gui,F:Margin,20,10 576 | Gui,F:Add, Text, xm y+10 w60, 规则名: 577 | Gui,F:Add, DropDownList, xm+60 yp Choose%RuleNameChoose% vvRuleName, %rulenameStr% 578 | Gui,F:Add, Radio, xm y+10 Checked%FuncBoolean1% vvFuncBoolean1, 相等、真(&T) 579 | Gui,F:Add, Radio, x+5 yp Checked%FuncBoolean2% vvFuncBoolean2, 不相等、假(&F) 580 | Gui,F:Add, CheckBox, x+20 yp Checked%FuncBreak% vvFuncBreak, 不满足中断规则循环 581 | Gui,F:Add, Text, xm y+10 w350, 自定义条件(只判断规则真假,不用填写):`n(多个参数每行为一个参数,最多支持10个,保存会用|分隔) 582 | Gui,F:Add, Edit, xm y+10 w350 r8 vvFuncValue, %FuncValue% 583 | Gui,F:Add, Button,Default xm+80 y+15 w75 GLVFuncSave,保存(&Y) 584 | Gui,F:Add, Button,x+10 w75 GLVCancel,取消(&C) 585 | Gui,F:Show, , %RunAnyCtrl% 修改使用规则 586 | return 587 | LVFuncRemove: 588 | DelRowList:="" 589 | Row:=LV_GetNext(0, "F") 590 | RowNumber:=0 591 | if(Row) 592 | MsgBox,35,确认删除?(Esc取消),确定删除选中的规则项? 593 | Loop 594 | { 595 | RowNumber := LV_GetNext(RowNumber) ; 在前一次找到的位置后继续搜索. 596 | if not RowNumber ; 上面返回零, 所以选择的行已经都找到了. 597 | break 598 | IfMsgBox Yes 599 | { 600 | DelRowList:=RowNumber . ":" . DelRowList 601 | } 602 | } 603 | IfMsgBox Yes 604 | { 605 | stringtrimright, DelRowList, DelRowList, 1 606 | loop, parse, DelRowList, : 607 | LV_Delete(A_loopfield) 608 | } 609 | return 610 | LVFuncSave: 611 | Gui,F:Submit, NoHide 612 | if(!vRuleName){ 613 | MsgBox, 48, ,请选择使用的规则 614 | return 615 | } 616 | if(InStr(vFuncValue,"|")){ 617 | MsgBox, 48, ,自定义条件不能包含有“|”,因为每个参数保存用“|”进行分隔 618 | return 619 | } 620 | vFuncValueNums:=StrSplit(vFuncValue,"`n") 621 | if(vFuncValueNums.MaxIndex() > 10){ 622 | MsgBox, 48, ,自定义条件每行为一个参数,最多支持10行 623 | return 624 | } 625 | funcValueStr:="" 626 | Loop,% vFuncValueNums.MaxIndex() 627 | { 628 | if(vFuncValueNums[A_Index]) 629 | funcValueStr.=vFuncValueNums[A_Index] . "|" 630 | } 631 | stringtrimright, funcValueStr, funcValueStr, 1 632 | ;[写入配置文件] 633 | Gui,F:Destroy 634 | Gui,2:Default 635 | vFuncBoolean:=vFuncBoolean1 ? 1 : 0 636 | if(menuFuncItem="修改规则函数"){ 637 | LV_Modify(RowNumber,"",vRuleName,vFuncBreak ? "*" : "",vFuncBoolean ? "相等" : "不相等",funcValueStr) 638 | }else{ 639 | LV_Add("",vRuleName,vFuncBreak ? "*" : "",vFuncBoolean ? "相等" : "不相等",funcValueStr) 640 | } 641 | LV_ModifyCol(1) 642 | LV_ModifyCol(2) 643 | LV_ModifyCol(3) 644 | GuiControl, 2:+Redraw, FuncLV 645 | return 646 | listfunc: 647 | if A_GuiEvent = DoubleClick 648 | { 649 | gosub,LVFuncEdit 650 | } 651 | return 652 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 653 | #If WinActive(RunAnyCtrl A_Space "启动控制器") 654 | F1::gosub,LVRun 655 | F2::gosub,LVConfig 656 | F3::gosub,LVAdd 657 | F4::gosub,LVSuspend 658 | F5::gosub,LVPause 659 | F6::gosub,LVClose 660 | Del::gosub,LVDel 661 | F7::gosub,LVEdit 662 | F8::gosub,LVImport 663 | F9::gosub,LVSet 664 | F10::gosub,LVRule 665 | #If 666 | GuiContextMenu: 667 | If (A_GuiControl = "RunAnyLV") { 668 | LV_Modify(A_EventInfo, "Select Vis") 669 | Menu, LVMenu, Show 670 | } 671 | return 672 | GuiSize: 673 | RGuiSize: 674 | if A_EventInfo = 1 675 | return 676 | GuiControl, Move, RunAnyLV, % "H" . (A_GuiHeight-10) . " W" . (A_GuiWidth - 20) 677 | GuiControl, Move, RuleLV, % "H" . (A_GuiHeight-10) . " W" . (A_GuiWidth - 20) 678 | return 679 | GuiClose: 680 | Gui,Destroy 681 | return 682 | GuiEscape: 683 | Gui,Destroy 684 | return 685 | LVCancel: 686 | Gui,Destroy 687 | return 688 | listview: 689 | if A_GuiEvent = DoubleClick 690 | { 691 | menuItem:="配置" 692 | gosub,GuiConfig 693 | } 694 | return 695 | SetFilePath: 696 | FileSelectFile, filePath, 3, , 请选择导入的启动项, (*.ahk;*.exe) 697 | GuiControl, 2:, vFilePath, %filePath% 698 | return 699 | ;[全路径转换为RunAnyCtrl的相对路径] 700 | SetFileRelativePath: 701 | Gui,2:Submit, NoHide 702 | funcResult:=IsFunc("funcPath2RelativeZz") ? Func("funcPath2RelativeZz").Call(vFilePath,A_ScriptFullPath) : 0 703 | if(funcResult=-1){ 704 | ToolTip, 路径有误,155,180 705 | SetTimer,RemoveToolTip,5000 706 | return 707 | } 708 | if(funcResult=-2){ 709 | ToolTip, 与RunAnyCtrl不在同一磁盘,不能转换为相对路径,155,180 710 | SetTimer,RemoveToolTip,5000 711 | return 712 | } 713 | if(funcResult){ 714 | GuiControl, 2:, vFilePath, %funcResult% 715 | } 716 | return 717 | LVSet: 718 | Gui,S:Destroy 719 | Gui,S:Margin,50,30 720 | Gui,S:Add, Checkbox,Checked%AutoRun% xm yp+10 h30 vvAutoRun,开机自动启动 721 | Gui,S:Add, Checkbox,Checked%AdminRun% x+5 yp h30 vvAdminRun,管理员权限启动 722 | Gui,S:Add, GroupBox,xm-10 y+10 w225 h55,RunAnyCtrl配置自定义热键 %ConfigHotKey% 723 | Gui,S:Add, Hotkey,xm yp+20 w150 vvConfigKey,%ConfigKey% 724 | Gui,S:Add, Checkbox,Checked%ConfigWinKey% xm+155 yp+3 vvConfigWinKey,Win 725 | Gui,S:Add, Button,Default xm+15 y+30 w75 GLVSetSave,保存(&Y) 726 | Gui,S:Add, Button,x+10 w75 GLVCancel,取消(&C) 727 | Gui,S:Show, , %RunAnyCtrl% 设置选项 728 | return 729 | LVSetSave: 730 | Gui,S:Submit 731 | reloadFlag:=false 732 | if(vAutoRun!=AutoRun){ 733 | AutoRun:=vAutoRun 734 | if(AutoRun){ 735 | scriptName:=FileExist("RunAnyCtrl.exe") ? "RunAnyCtrl.exe" : A_ScriptName 736 | RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, RunAnyCtrl, %A_ScriptDir%\%scriptName% 737 | }else{ 738 | RegDelete, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, RunAnyCtrl 739 | } 740 | reloadFlag:=true 741 | } 742 | if(vAdminRun!=AdminRun){ 743 | IniWrite,%vAdminRun%,%iniFile%,run_any_ctrl_config,AdminRun 744 | reloadFlag:=true 745 | } 746 | if(vConfigKey!=ConfigKey){ 747 | IniWrite,%vConfigKey%,%iniFile%,run_any_ctrl_config,ConfigKey 748 | reloadFlag:=true 749 | } 750 | if(vConfigWinKey!=ConfigWinKey){ 751 | IniWrite,%vConfigWinKey%,%iniFile%,run_any_ctrl_config,ConfigWinKey 752 | reloadFlag:=true 753 | } 754 | if(reloadFlag) 755 | Reload 756 | return 757 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 758 | ;~;[规则配置] 759 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 760 | LVRule: 761 | gosub,Rule_Item_Read 762 | Gui,R:Destroy 763 | Gui,R:Default 764 | Gui,R:+Resize 765 | Gui,R:Font, s10, Microsoft YaHei 766 | Gui,R:Add, Listview, xm w600 r18 grid AltSubmit BackgroundF6F6E8 vRuleLV glistrule, 规则名|规则函数|状态|规则路径 767 | ;[读取规则内容写入列表] 768 | GuiControl, -Redraw, RuleLV 769 | For ki, kv in ruleitemList 770 | { 771 | LV_Add("", ki, rulefuncList[ki], rulestatusList[ki] ? "正常" : "不可用", kv) 772 | } 773 | GuiControl, +Redraw, RuleLV 774 | Menu, ruleGuiMenu, Add, 增加, LVRulePlus 775 | Menu, ruleGuiMenu, Icon, 增加, SHELL32.dll,1 776 | Menu, ruleGuiMenu, Add, 编辑, LVRuleEdit 777 | Menu, ruleGuiMenu, Icon, 编辑, SHELL32.dll,134 778 | Menu, ruleGuiMenu, Add, 减少, LVRuleMinus 779 | Menu, ruleGuiMenu, Icon, 减少, SHELL32.dll,132 780 | Gui,R:Menu, ruleGuiMenu 781 | LV_ModifyCol() ; 根据内容自动调整每列的大小. 782 | Gui,R:Show, , %RunAnyCtrl% 规则管理 783 | return 784 | LVRulePlus: 785 | menuRuleItem:="规则新建" 786 | RuleName:=RuleFunction:=RulePath:="" 787 | gosub,LVRuleConfig 788 | return 789 | LVRuleEdit: 790 | RowNumber:=LV_GetNext(0, "F") 791 | if not RowNumber 792 | return 793 | LV_GetText(RuleName, RowNumber, 1) 794 | LV_GetText(RuleFunction, RowNumber, 2) 795 | LV_GetText(RulePath, RowNumber, 4) 796 | menuRuleItem:="规则编辑" 797 | gosub,LVRuleConfig 798 | return 799 | LVRuleConfig: 800 | Gui,P:Destroy 801 | Gui,P:Font,,Microsoft YaHei 802 | Gui,P:Margin,20,10 803 | Gui,P:Add, Text, xm y+10 w60, 规则名: 804 | Gui,P:Add, Edit, xm+60 yp-3 w450 vvRuleName, %RuleName% 805 | Gui,P:Add, Text, xm y+10 w60, 规则函数: 806 | Gui,P:Add, Edit, xm+60 yp-3 w225 vvRuleFunction, %RuleFunction% 807 | Gui,P:Add, DropDownList, x+5 yp+2 w220 vvRuleDLL GDropDownRuleList 808 | Gui,P:Add, Button, xm-5 yp+30 w60 h60 GSetRulePath,规则路径 可自动识别函数名 809 | Gui,P:Add, Edit, xm+60 yp w450 r3 vvRulePath GRulePathChange, %RulePath% 810 | Gui,P:Add, Button,Default xm+180 y+10 w75 GLVRuleSave,保存(&Y) 811 | Gui,P:Add, Button,x+10 w75 GLVCancel,取消(&C) 812 | Gui,P:Show, , %RunAnyCtrl% 规则编辑 813 | funcnameStr:=KnowAhkFuncZz(RulePath) 814 | GuiControl, P:, vRuleDLL, | 815 | GuiControl, P:, vRuleDLL, %funcnameStr% 816 | funcNameChoose:=1 817 | loop, parse, funcnameStr, | 818 | { 819 | if(RuleFunction=A_LoopField){ 820 | funcNameChoose:=A_Index 821 | break 822 | } 823 | } 824 | GuiControl, P:Choose, vRuleDLL, %funcNameChoose% 825 | return 826 | LVRuleMinus: 827 | DelRowList:="" 828 | Row:=LV_GetNext(0, "F") 829 | RowNumber:=0 830 | if(Row) 831 | MsgBox,35,确认删除?(Esc取消),确定删除选中的规则项? 832 | Loop 833 | { 834 | RowNumber := LV_GetNext(RowNumber) ; 在前一次找到的位置后继续搜索. 835 | if not RowNumber ; 上面返回零, 所以选择的行已经都找到了. 836 | break 837 | IfMsgBox Yes 838 | { 839 | LV_GetText(RuleName, RowNumber, 1) 840 | LV_GetText(RuleFunction, RowNumber, 2) 841 | LV_GetText(RulePath, RowNumber, 4) 842 | DelRowList:=RowNumber . ":" . DelRowList 843 | IniDelete, %iniFile%, rule_item, %RuleName% 844 | IniDelete, %iniFile%, func_item, %RuleName% 845 | ;删除所有正在使用此规则的关联配置 846 | Change_Rule_Name(RuleName,"") 847 | gosub,Rule_Item_Read 848 | ;~ 判断如果所有规则都没用到此脚本,则去除引用 849 | NoQuote:=true 850 | For ki, kv in ruleitemList 851 | { 852 | if(RulePath=kv) 853 | NoQuote:=false 854 | } 855 | if(NoQuote){ 856 | oldRule:="#Include *i " RulePath 857 | Plugins_Replace(oldRule) 858 | gosub,Plugins_Read 859 | } 860 | } 861 | } 862 | IfMsgBox Yes 863 | { 864 | stringtrimright, DelRowList, DelRowList, 1 865 | loop, parse, DelRowList, : 866 | LV_Delete(A_loopfield) 867 | } 868 | return 869 | LVRuleSave: 870 | Gui,P:Submit, NoHide 871 | if(!vRuleName || !vRuleFunction || !vRulePath){ 872 | MsgBox, 48, ,请填入规则名、规则函数和规则路径 873 | return 874 | } 875 | if(InStr(vRuleName,"|")){ 876 | MsgBox, 48, ,规则名不能包含有“|”分割符 877 | return 878 | } 879 | if(RuleName!=vRuleName && ruleitemList[vRuleName]){ 880 | MsgBox, 48, ,已存在相同的规则名,请修改 881 | return 882 | } 883 | StringReplace, checkRulePath, vRulePath,`%A_ScriptDir`%, %A_ScriptDir% 884 | IfNotExist,%checkRulePath% 885 | { 886 | MsgBox, 48, ,规则路径AHK脚本不存在,请重新添加 887 | return 888 | } 889 | ;[写入配置文件] 890 | Gui,R:Default 891 | includeStr:="#Include *i " 892 | if(menuRuleItem="规则编辑"){ 893 | if(RuleName!=vRuleName){ 894 | IniDelete, %iniFile%, rule_item, %RuleName% 895 | IniDelete, %iniFile%, func_item, %RuleName% 896 | ;~ 变更所有正在使用此规则的启动项中关联规则名称 897 | Change_Rule_Name(RuleName,vRuleName) 898 | } 899 | if(!pluginsList[includeStr . vRulePath]){ 900 | oldRule:=includeStr . RulePath 901 | appendRule:=includeStr . vRulePath 902 | Plugins_Replace(oldRule,appendRule) 903 | } 904 | LV_Modify(RowNumber,"",vRuleName,vRuleFunction,IsFunc(vRuleFunction) ? "正常" : "不可用",vRulePath) 905 | }else{ 906 | if(!pluginsList[includeStr . vRulePath]){ 907 | FileAppend,% "`n" . includeStr . vRulePath,%pluginsFile% 908 | } 909 | LV_Add("",vRuleName,vRuleFunction,"重启生效",vRulePath) 910 | } 911 | LV_ModifyCol() ; 根据内容自动调整每列的大小. 912 | GuiControl, R:+Redraw, RuleLV 913 | IniWrite, %vRulePath%, %iniFile%, rule_item, %vRuleName% 914 | IniWrite, %vRuleFunction%, %iniFile%, func_item, %vRuleName% 915 | gosub,Plugins_Read 916 | gosub,Rule_Item_Read 917 | Gui,P:Destroy 918 | return 919 | listrule: 920 | if A_GuiEvent = DoubleClick 921 | { 922 | gosub,LVRuleEdit 923 | } 924 | return 925 | SetRulePath: 926 | FileSelectFile, rulePath, 3, , 请选择要使用的的AutoHotkey规则脚本, (*.ahk) 927 | if(rulePath){ 928 | Gui,P:Submit, NoHide 929 | Get_Rule_Func_Name(rulePath,vRuleFunction) 930 | GuiControl, P:, vRulePath, %rulePath% 931 | } 932 | return 933 | RulePathChange: 934 | Gui,P:Submit, NoHide 935 | Get_Rule_Func_Name(vRulePath,vRuleFunction) 936 | return 937 | DropDownRuleList: 938 | Gui,P:Submit, NoHide 939 | GuiControl, P:, vRuleFunction, %vRuleDLL% 940 | return 941 | ;[自动根据规则脚本的路径来变更函数下拉选择框和空规则函数] 942 | Get_Rule_Func_Name(rulePath,vRuleFunction){ 943 | if(rulePath){ 944 | funcnameStr:=KnowAhkFuncZz(rulePath) 945 | GuiControl, P:, vRuleDLL, | 946 | GuiControl, P:, vRuleDLL, %funcnameStr% 947 | GuiControl, P:Choose, vRuleDLL, 1 948 | if(!vRuleFunction && funcnameStr){ 949 | gosub,DropDownRuleList 950 | } 951 | } 952 | } 953 | ;[判断脚本当前状态] 954 | LVStatusChange(RowNumber,FileStatus,lvItem){ 955 | item:=lvItem 956 | if(FileStatus="挂起" && lvItem="暂停"){ 957 | lvItem:="挂起暂停" 958 | }else if(FileStatus="暂停" && lvItem="挂起"){ 959 | lvItem:="暂停挂起" 960 | }else if(FileStatus!="启动"){ 961 | StringReplace, lvItem, FileStatus, %item% 962 | } 963 | if(lvItem="") 964 | lvItem:="启动" 965 | LV_Modify(RowNumber, "", , , , , , , , , , , , lvItem) 966 | LVModifyCol(38,ColumnAutoRun,ColumnHideRun,ColumnCloseRun,ColumnRepeatRun,ColumnRuleRun,ColumnRuleLogic) ; 根据内容自动调整每列的大小. 967 | } 968 | ;[自动调整列表宽度] 969 | LVModifyCol(width, colList*){ 970 | LV_ModifyCol() ; 根据内容自动调整每列的大小. 971 | for index,col in colList 972 | { 973 | LV_ModifyCol(col, width) 974 | LV_ModifyCol(col, "center") 975 | } 976 | } 977 | ;[变更所有正在使用此规则的启动项中关联规则名称] 978 | Change_Rule_Name(rname,rnew){ 979 | global run_item_List 980 | For runn, runv in run_item_List 981 | { 982 | writeFalg:=false 983 | ruleContent:="" 984 | IniRead,runRuleVar,%iniFile%,%runn% 985 | Loop, parse, runRuleVar, `n, `r 986 | { 987 | runRuleSplit:="" 988 | Loop, parse, A_LoopField, | 989 | { 990 | if(A_Index=1 && A_LoopField=rname){ 991 | writeFalg:=true 992 | if(rnew){ 993 | runRuleSplit.=rnew . "|" 994 | continue 995 | }else{ 996 | break 997 | } 998 | } 999 | runRuleSplit.=A_LoopField . "|" 1000 | } 1001 | stringtrimright, runRuleSplit, runRuleSplit, 1 1002 | ruleContent.=runRuleSplit . "`n" 1003 | } 1004 | if(writeFalg){ 1005 | IniDelete, %iniFile%, %runn% 1006 | stringtrimright, ruleContent, ruleContent, 1 1007 | IniWrite, %ruleContent%, %iniFile%, %runn% 1008 | } 1009 | } 1010 | } 1011 | ;[替换嵌入脚本的文本,需要重启生效] 1012 | Plugins_Replace(oldPlugins,newPlugins:=""){ 1013 | content:="" 1014 | FileRead, pluginsContent, %pluginsFile% 1015 | Loop, parse, pluginsContent, `n, `r 1016 | { 1017 | if(A_LoopField=oldPlugins){ 1018 | content.=newPlugins 1019 | if(newPlugins) 1020 | content.="`n" 1021 | }else{ 1022 | content.=A_LoopField "`n" 1023 | } 1024 | } 1025 | stringtrimright, content, content, 1 1026 | FileDelete,%pluginsFile% 1027 | FileAppend,%content%,%pluginsFile% 1028 | } 1029 | Check_IsRun(runv){ 1030 | return IsFunc("rule_IsRun") ? Func("rule_IsRun").Call(runv) : false 1031 | } 1032 | KnowAhkFuncZz(RulePath){ 1033 | return IsFunc("getAhkFuncZz") ? Func("getAhkFuncZz").Call(RulePath) : "" 1034 | } 1035 | Var_Read(rValue,defVar=""){ 1036 | RegRead, regVar, HKEY_CURRENT_USER, SOFTWARE\%RunAnyCtrl%, %rValue% 1037 | if(regVar) 1038 | return regVar 1039 | else 1040 | return defVar 1041 | } 1042 | Reg_Set(sz,var){ 1043 | RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\%RunAnyCtrl%, %sz%, %var% 1044 | } 1045 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 1046 | ;~;[生效规则] 1047 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 1048 | Rule_Effect: 1049 | global runIndex:=Object(),funcEffect:=Object() 1050 | try{ 1051 | For runn, runv in run_item_List ;循环启动项 1052 | { 1053 | if(rule_run_item_List[runn]){ ;需要执行规则 1054 | ;已在运行且设定为不重复启动 1055 | if(repeat_run_item_List[runn] && Check_IsRun(runv)) 1056 | continue 1057 | ;是否设定运行项最多启动次数 1058 | if(most_run_item_List[runn] && !mostrunIndex[runn]) 1059 | mostrunIndex[runn]:=0 1060 | if((rule_number_item_List[runn] && rule_number_item_List[runn] > 1) || (rule_number_item_List[runn] > 0 && rule_time_item_List[runn])){ 1061 | runIndex[runn]:=0 ;规则定时器初始计数为0 1062 | funcEffect%runn%:=Func("Func_Effect").Bind(runn, runv) ;规则定时器 1063 | ruleTime:=rule_time_item_List[runn] ? rule_time_item_List[runn] : 1 ;规则定时器间隔时间(毫秒) 1064 | SetTimer,% funcEffect%runn%, %ruleTime% 1065 | }else{ 1066 | Func_Effect(runn, runv) 1067 | } 1068 | } 1069 | } 1070 | } catch e { 1071 | MsgBox,16,规则启动出错,% "启动项名:" runn "`n启动项路径:" runv "`n出错脚本:" e.File "`n出错命令:" e.What "`n错误代码行:" e.Line "`n错误信息:" e.extra "`n" e.message 1072 | } 1073 | return 1074 | /* 1075 | [规则嵌入函数验证] 1076 | 最多支持传递10个参数 1077 | */ 1078 | Func_Effect(runn, runv){ 1079 | global 1080 | Critical 1081 | effectFlag:=false 1082 | For k, v in runruleitemList[runn] ;循环规则内容 1083 | { 1084 | if(!v["ruleParam"]){ ;规则没有传参,直接执行规则 1085 | effectFlag:=funccallList[v["ruleName"]].Call() 1086 | }else if(v["ruleParam"].MaxIndex()=1){ 1087 | effectFlag:=v["ruleParam"][1] ? funccallList[v["ruleName"]].Call(v["ruleParam"][1]) : funccallList[v["ruleName"]].Call() 1088 | }else if(v["ruleParam"].MaxIndex()=2){ 1089 | effectFlag:=funccallList[v["ruleName"]].Call(v["ruleParam"][1],v["ruleParam"][2]) 1090 | }else if(v["ruleParam"].MaxIndex()=3){ 1091 | effectFlag:=funccallList[v["ruleName"]].Call(v["ruleParam"][1],v["ruleParam"][2],v["ruleParam"][3]) 1092 | }else if(v["ruleParam"].MaxIndex()=4){ 1093 | effectFlag:=funccallList[v["ruleName"]].Call(v["ruleParam"][1],v["ruleParam"][2],v["ruleParam"][3],v["ruleParam"][4]) 1094 | }else if(v["ruleParam"].MaxIndex()=5){ 1095 | effectFlag:=funccallList[v["ruleName"]].Call(v["ruleParam"][1],v["ruleParam"][2],v["ruleParam"][3],v["ruleParam"][4],v["ruleParam"][5]) 1096 | }else if(v["ruleParam"].MaxIndex()=6){ 1097 | effectFlag:=funccallList[v["ruleName"]].Call(v["ruleParam"][1],v["ruleParam"][2],v["ruleParam"][3],v["ruleParam"][4],v["ruleParam"][5],v["ruleParam"][6]) 1098 | }else if(v["ruleParam"].MaxIndex()=7){ 1099 | effectFlag:=funccallList[v["ruleName"]].Call(v["ruleParam"][1],v["ruleParam"][2],v["ruleParam"][3],v["ruleParam"][4],v["ruleParam"][5],v["ruleParam"][6],v["ruleParam"][7]) 1100 | }else if(v["ruleParam"].MaxIndex()=8){ 1101 | effectFlag:=funccallList[v["ruleName"]].Call(v["ruleParam"][1],v["ruleParam"][2],v["ruleParam"][3],v["ruleParam"][4],v["ruleParam"][5],v["ruleParam"][6],v["ruleParam"][7],v["ruleParam"][8]) 1102 | }else if(v["ruleParam"].MaxIndex()=9){ 1103 | effectFlag:=funccallList[v["ruleName"]].Call(v["ruleParam"][1],v["ruleParam"][2],v["ruleParam"][3],v["ruleParam"][4],v["ruleParam"][5],v["ruleParam"][6],v["ruleParam"][7],v["ruleParam"][8],v["ruleParam"][9]) 1104 | }else if(v["ruleParam"].MaxIndex()=10){ 1105 | effectFlag:=funccallList[v["ruleName"]].Call(v["ruleParam"][1],v["ruleParam"][2],v["ruleParam"][3],v["ruleParam"][4],v["ruleParam"][5],v["ruleParam"][6],v["ruleParam"][7],v["ruleParam"][8],v["ruleParam"][9],v["ruleParam"][10]) 1106 | } 1107 | ;如果规则设定条件为(不相等、假),而脚本执行结果是真,则判定为false;执行结果是假,则判定为true 1108 | if(!v["ruleLogic"]){ 1109 | effectFlag:=effectFlag ? false : true 1110 | } 1111 | ;规则不满足且有中断标记则直接中断后续判断并停止规则循环 1112 | if(!effectFlag && v["ruleBreak"]){ 1113 | try SetTimer,% funcEffect%runn%, Off 1114 | break 1115 | } 1116 | ;该启动项所有规则必须全部为真时,如有一假就退出循环 1117 | ;该启动项只需要有一项规则为真时,如有一真就退出循环 1118 | if(rule_logic_item_List[runn]){ 1119 | if(!effectFlag) 1120 | break 1121 | }else{ 1122 | if(effectFlag) 1123 | break 1124 | } 1125 | } 1126 | if(effectFlag){ 1127 | ;启动项是否超出最多运行次数 1128 | if(!most_run_item_List[runn] || mostrunIndex[runn] < most_run_item_List[runn]){ 1129 | Run_Run_Run(runn,runv) 1130 | if(most_run_item_List[runn]) 1131 | mostrunIndex[runn]++ 1132 | } 1133 | } 1134 | runIndex[runn]++ ;规则定时器运行计数+1 1135 | ;规则运行计数达到最大循环次数 || 已在运行且设定为不重复启动 || 启动项已达到最多运行次数 => 结束定时器 1136 | if((runIndex[runn] && runIndex[runn] >= rule_number_item_List[runn]) || (repeat_run_item_List[runn] && Check_IsRun(runv)) || (most_run_item_List[runn] && mostrunIndex[runn] >= most_run_item_List[runn])){ 1137 | try SetTimer,% funcEffect%runn%, Off 1138 | } 1139 | } 1140 | ;~;[自动启动生效] 1141 | AutoRun_Effect: 1142 | try { 1143 | For runn, runv in run_item_List ;循环启动项 1144 | { 1145 | ;需要自动启动的项 1146 | if(auto_run_item_List[runn]){ 1147 | ;已在运行且设定为不重复启动 1148 | if(repeat_run_item_List[runn] && Check_IsRun(runv)) 1149 | continue 1150 | ;设定为延迟启动 1151 | if(delay_run_item_List[runn]){ 1152 | delayRunEffect%runn%:=Func("Delay_Run_Effect").Bind(runn,runv) 1153 | SetTimer,% delayRunEffect%runn%, % delay_run_item_List[runn] 1154 | continue 1155 | } 1156 | Run_Run_Run(runn,runv) 1157 | } 1158 | } 1159 | } catch e { 1160 | MsgBox,16,自动启动出错,% "启动项名:" runn "`n启动项路径:" runv "`n出错脚本:" e.File "`n出错命令:" e.What "`n错误代码行:" e.Line "`n错误信息:" e.extra "`n" e.message 1161 | } 1162 | return 1163 | ;~;[随RunAnyCtrl自动关闭] 1164 | AutoClose_Effect: 1165 | For runn, runv in run_item_List 1166 | { 1167 | if(close_run_item_List[runn]){ 1168 | runValue:=RegExReplace(runv,"iS)(.*?\.exe)($| .*)","$1") ;去掉参数 1169 | SplitPath, runValue, name,, ext ; 获取扩展名 1170 | if(ext="ahk"){ 1171 | if(InStr(runv,"..\")=1){ 1172 | runv:=IsFunc("funcPath2AbsoluteZz") ? Func("funcPath2AbsoluteZz").Call(runv,A_ScriptFullPath) : runv 1173 | } 1174 | PostMessage, 0x111, 65405,,, %runv% ahk_class AutoHotkey 1175 | }else if(name){ 1176 | Process,Close,%name% 1177 | } 1178 | } 1179 | } 1180 | return 1181 | Run_Run_Run(runn,runv){ 1182 | global 1183 | try { 1184 | if(InStr(runv,"..\")=1){ 1185 | runv:=IsFunc("funcPath2AbsoluteZz") ? Func("funcPath2AbsoluteZz").Call(runv,A_ScriptFullPath) : runv 1186 | } 1187 | runValue:=RegExReplace(runv,"iS)(.*?\.exe)($| .*)","$1") ;去掉参数 1188 | SplitPath, runValue, , dir, ext 1189 | if(dir && FileExist(dir)){ 1190 | SetWorkingDir,%dir% 1191 | } 1192 | ;设定为隐藏启动 1193 | if(hide_run_item_List[runn]){ 1194 | Run,%runv%,, hide 1195 | }else{ 1196 | Run,%runv% 1197 | } 1198 | IniWrite, %A_Now%, %iniFileLastRunTime%, last_run_time, %runn% 1199 | } catch e { 1200 | MsgBox,16,启动出错,% "启动项名:" runn "`n启动项路径:" runv "`n出错脚本:" e.File "`n出错命令:" e.What "`n错误代码行:" e.Line "`n错误信息:" e.extra "`n" e.message 1201 | } finally { 1202 | SetWorkingDir,%A_ScriptDir% 1203 | } 1204 | } 1205 | Delay_Run_Effect(runn,runv){ 1206 | Run_Run_Run(runn,runv) 1207 | SetTimer,% delayRunEffect%runn%, Off 1208 | } 1209 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 1210 | ;~;[初始化] 1211 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 1212 | Var_Set: 1213 | ;~;[RunAnyCtrl设置参数] 1214 | RegRead, AutoRun, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, RunAnyCtrl 1215 | AutoRun:=AutoRun ? 1 : 0 1216 | IniRead, AdminRun,%iniFile%, run_any_ctrl_config, AdminRun 1217 | AdminRun:=AdminRun=1 ? 1 : 0 1218 | ;配置列表:RunAnyCtrl配置;启动路径;规则路径;规则函数;自动启动;隐藏启动;关闭启动;不重复启动;最多启动次数;延迟启动时间;最后运行时间;规则启动;规则逻辑;循环次数;循环间隔时间 1219 | global KeyList:=["run_any_ctrl_config","run_item","rule_item","func_item","auto_run_item","hide_run_item","close_run_item","repeat_run_item","most_run_item","delay_run_item","rule_run_item","rule_logic_item","rule_number_item","rule_time_item"] 1220 | global RunKeyList=KeyList.Clone() ;对象拷贝 1221 | RunKeyList.RemoveAt(4) 1222 | RunKeyList.RemoveAt(3) 1223 | RunKeyList.RemoveAt(1) 1224 | gosub,Init_Set 1225 | ;配置界面的热键 1226 | IniRead, ConfigKey,%iniFile%, run_any_ctrl_config, ConfigKey 1227 | IniRead, ConfigWinKey,%iniFile%, run_any_ctrl_config, ConfigWinKey 1228 | ConfigHotKey:=ConfigWinKey ? "#" . ConfigKey : ConfigKey 1229 | try Hotkey,%ConfigHotKey%,LV_Show,On 1230 | global mostrunIndex:=Object() 1231 | global iniFileLastRunTime:=A_AppData "\RunAnyCtrl\RACLastRunTime.ini" 1232 | gosub,Plugins_Read 1233 | return 1234 | ;~;[配置文件初始化操作] 1235 | Init_Set: 1236 | IfNotExist,%A_ScriptDir%\Lib 1237 | { 1238 | FileCreateDir, %A_ScriptDir%\Lib 1239 | } 1240 | IfNotExist,%A_AppData%\RunAnyCtrl 1241 | { 1242 | FileCreateDir, %A_AppData%\RunAnyCtrl 1243 | } 1244 | if(FileExist(iniFileLastRunTime)){ 1245 | FileAppend,"",%iniFileLastRunTime% 1246 | } 1247 | IfNotExist,%iniFile% 1248 | { 1249 | initIniContent:="" 1250 | initRun:="RunAnyCtrl=https://github.com/hui-Zz/RunAnyCtrl" 1251 | initRule:="网络连接=%A_ScriptDir%\Lib\rule_common.ahk`n电脑名=%A_ScriptDir%\Lib\rule_common.ahk`nWiFi名(静默)=%A_ScriptDir%\Lib\rule_common.ahk`n运行状态=%A_ScriptDir%\Lib\rule_common.ahk`n时间点=%A_ScriptDir%\Lib\rule_time.ahk`n星期几=%A_ScriptDir%\Lib\rule_time.ahk" 1252 | initFunc:="网络连接=rule_network`n电脑名=rule_computer_name`nWiFi名(静默)=rule_wifi_silence`n运行状态=rule_IsRun`n时间点=rule_today_hour`n星期几=rule_today_week" 1253 | For ki, kv in KeyList 1254 | { 1255 | initIniContent.="[" kv "]`n" 1256 | } 1257 | FileAppend,%initIniContent%,%iniFile% 1258 | IniWrite, %initRun%, %iniFile%, run_item 1259 | IniWrite, %initRule%, %iniFile%, rule_item 1260 | IniWrite, %initFunc%, %iniFile%, func_item 1261 | IniWrite, 1, %iniFile%, rule_run_item, RunAnyCtrl 1262 | IniWrite, 网络连接|1|, %iniFile%, RunAnyCtrl 1263 | Gosub,Github_Update 1264 | TrayTip,,RunAnyCtrl初始化成功!点击任务栏图标设置,可自由定制规则启动程序(如有网络打开网页),3,1 1265 | } 1266 | if(FileExist(pluginsFile)) 1267 | FileRead, pluginsVar, %pluginsFile% 1268 | if(!FileExist(pluginsFile) || !pluginsVar){ 1269 | TrayTip,,RunAnyCtrl初始化生成导入规则函数%A_ScriptDir%\Lib\RunAnyCtrlPlugins.ahk,3,1 1270 | content:="" 1271 | commonAhk:="\Lib\rule_common.ahk" 1272 | timeAhk:="\Lib\rule_time.ahk" 1273 | if(FileExist(A_ScriptDir commonAhk)){ 1274 | content.="#Include *i %A_ScriptDir%" . commonAhk 1275 | } 1276 | if(FileExist(A_ScriptDir timeAhk)){ 1277 | content.="`n#Include *i %A_ScriptDir%" . timeAhk 1278 | } 1279 | FileAppend,%content%,%pluginsFile% 1280 | Reload 1281 | } 1282 | return 1283 | ;~;[规则插件内容] 1284 | Plugins_Read: 1285 | global pluginsList:=Object() 1286 | global pluginsContent:="" 1287 | FileRead, pluginsContent, %pluginsFile% 1288 | Loop, parse, pluginsContent, `n, `r 1289 | { 1290 | pluginsList[A_LoopField]:=1 1291 | } 1292 | return 1293 | ;~;[启动项数据] 1294 | Run_Item_Read: 1295 | For ki, kv in RunKeyList 1296 | { 1297 | ;动态初始化 1298 | %kv%_List:=Object() 1299 | itemVar:="" 1300 | IniRead,itemVar,%iniFile%,%kv% 1301 | Loop, parse, itemVar, `n, `r 1302 | { 1303 | itemList:=StrSplit(A_LoopField,"=") 1304 | IniRead, OutputVar, %iniFile%, %kv%,% itemList[1] 1305 | %kv%_List[itemList[1]]:=OutputVar 1306 | } 1307 | } 1308 | last_run_time_List:=Object() 1309 | IniRead,itemVar,%iniFileLastRunTime%,last_run_time 1310 | Loop, parse, itemVar, `n, `r 1311 | { 1312 | itemList:=StrSplit(A_LoopField,"=") 1313 | last_run_time_List[itemList[1]]:=itemList[2] 1314 | } 1315 | return 1316 | ;~;[规则数据] 1317 | Rule_Item_Read: 1318 | ;规则名-脚本路径列表;规则名-函数名列表;规则名-状态列表;规则名-执行列表;每项启动项设置的规则内容 1319 | global ruleitemList:=Object(),rulefuncList:=Object(),rulestatusList:=Object(),funccallList:=Object(),runruleitemList:=Object() 1320 | global rulenameStr:="" 1321 | ruleitemVar:=rulefuncVar:="" 1322 | IniRead,ruleitemVar,%iniFile%,rule_item 1323 | Loop, parse, ruleitemVar, `n, `r 1324 | { 1325 | itemList:=StrSplit(A_LoopField,"=") 1326 | rulenameStr.=itemList[1] "|" 1327 | IniRead, OutputVar, %iniFile%, rule_item,% itemList[1] 1328 | ruleitemList[itemList[1]]:=OutputVar 1329 | IniRead,rulefuncVar,%iniFile%,func_item,% itemList[1] 1330 | rulefuncList[itemList[1]]:=rulefuncVar 1331 | rulestatusList[itemList[1]]:=IsFunc(rulefuncVar) ? 1 : 0 1332 | if(rulestatusList[itemList[1]]){ 1333 | funccallList[itemList[1]]:=Func(rulefuncVar) 1334 | } 1335 | } 1336 | stringtrimright, rulenameStr, rulenameStr, 1 1337 | ;读取启动项设置的规则内容 1338 | For runn, runv in run_item_List 1339 | { 1340 | ruleArray:=Object() ;~规则内容队列 1341 | IniRead,runRuleVar,%iniFile%,%runn% 1342 | Loop, parse, runRuleVar, `n, `r 1343 | { 1344 | ruleObj:=Object(),ruleParamArray:=Object() ;~规则内容对象,规则参数队列 1345 | ruleParamStr:=ruleParamTen:="" 1346 | Loop, parse, A_LoopField, | 1347 | { 1348 | if(A_Index=1){ 1349 | ruleObj["ruleName"]:=A_LoopField 1350 | continue 1351 | } 1352 | if(A_Index=2){ 1353 | ruleLogicStr:=A_LoopField 1354 | if(InStr(A_LoopField, "*")){ 1355 | ruleObj["ruleBreak"]:=1 1356 | StringReplace, ruleLogicStr, A_LoopField, * 1357 | } 1358 | ruleObj["ruleLogic"]:=ruleLogicStr 1359 | continue 1360 | } 1361 | if(A_Index>=3 && A_Index<12){ 1362 | ruleParamStr.=A_LoopField . "|" 1363 | ruleParamArray.Insert(A_LoopField) 1364 | continue 1365 | } 1366 | if(A_Index>=12) 1367 | ruleParamTen.=A_LoopField . "|" 1368 | } 1369 | ;第十个参数及以上分隔参数,都归为第十参数 1370 | if(ruleParamTen){ 1371 | stringtrimright, ruleParamTen, ruleParamTen, 1 1372 | ruleParamStr.=ruleParamTen 1373 | ruleParamArray.Insert(ruleParamTen) 1374 | }else{ 1375 | stringtrimright, ruleParamStr, ruleParamStr, 1 1376 | } 1377 | ruleObj["ruleParamStr"]:=ruleParamStr 1378 | ruleObj["ruleParam"]:=ruleParamArray 1379 | ruleArray.Insert(ruleObj) 1380 | } 1381 | runruleitemList[runn]:=ruleArray 1382 | } 1383 | return 1384 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 1385 | ;~;[托盘菜单] 1386 | ;══════════════════════════════════════════════════════════════════════════════════════════════════════ 1387 | MenuTray: 1388 | Menu,Tray,NoStandard 1389 | zzIconLib:=FileExist(A_ScriptDir "\RunAnyCtrl.ico") ? "" : "\Lib\" 1390 | zzIcon:=A_ScriptDir zzIconLib "\RunAnyCtrl.ico" 1391 | if(FileExist(zzIcon)) 1392 | Menu,Tray,Icon,%zzIcon%,1 1393 | else 1394 | Menu,Tray,Icon,%ahkExePath%,2 1395 | Menu,Tray,add,启动管理(&Z),LV_Show 1396 | Menu,Tray,add,修改配置(&E),LV_Ini 1397 | Menu,Tray,add 1398 | Menu,Tray,add,检查更新(&U),Github_Update 1399 | Menu,Tray,add 1400 | Menu,Tray,add,重启(&R),Menu_Reload 1401 | Menu,Tray,add,挂起(&S),Menu_Suspend 1402 | Menu,Tray,add,暂停(&A),Menu_Pause 1403 | Menu,Tray,add,退出(&X),Menu_Exit 1404 | Menu,Tray,Default,启动管理(&Z) 1405 | Menu,Tray,Click,1 1406 | return 1407 | LV_Ini: 1408 | Run,%iniFile% 1409 | return 1410 | Github_Update: 1411 | if(!FileExist(A_ScriptDir "\" RunAnyCtrl "_Update.ahk")){ 1412 | RunAnyGithubDir:="https://raw.githubusercontent.com/hui-Zz/RunAnyCtrl/master" 1413 | URLDownloadToFile, %RunAnyGithubDir%/%RunAnyCtrl%_Update.ahk, %A_ScriptDir%\%RunAnyCtrl%_Update.ahk 1414 | } 1415 | Run,%RunAnyCtrl%_Update.ahk 1416 | return 1417 | Menu_Reload: 1418 | Reload 1419 | return 1420 | Menu_Suspend: 1421 | Menu,tray,ToggleCheck,挂起(&S) 1422 | Suspend 1423 | return 1424 | Menu_Pause: 1425 | Menu,tray,ToggleCheck,暂停(&A) 1426 | Pause 1427 | return 1428 | Menu_Exit: 1429 | ExitApp 1430 | return 1431 | RemoveToolTip: 1432 | SetTimer,RemoveToolTip,Off 1433 | ToolTip 1434 | return 1435 | ExitSub: 1436 | gosub,AutoClose_Effect 1437 | ExitApp -------------------------------------------------------------------------------- /RunAnyCtrl.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hui-Zz/RunAnyCtrl/bbc062af80de12c2d4832a18bdff1e9a06b702db/RunAnyCtrl.exe -------------------------------------------------------------------------------- /RunAnyCtrl_Update.ahk: -------------------------------------------------------------------------------- 1 | /* 2 | 【RunAnyCtrl检查更新Github上的最新版本】 3 | */ 4 | global RunAnyCtrl_update_version:="2.5.4" 5 | SetWorkingDir,%A_ScriptDir% ;~脚本当前工作目录 6 | global RunAnyCtrl:="RunAnyCtrl" 7 | global iniFile:=A_ScriptDir "\" RunAnyCtrl ".ini" 8 | updateMsg:=Object() 9 | updateNeed:=Object() 10 | notnewest:=true 11 | DownList:=["RunAnyCtrl","RunAnyCtrlFunc","JSON","rule_common","rule_time"] 12 | ;[下载最新的更新脚本] 13 | lpszUrl:="https://raw.githubusercontent.com" 14 | RunAnyGithubDir:=lpszUrl . "/hui-Zz/RunAnyCtrl/master" 15 | network:=DllCall("Wininet.dll\InternetCheckConnection", "Ptr", &lpszUrl, "UInt", 0x1, "UInt", 0x0, "Int") 16 | if(!network){ 17 | MsgBox,网络异常,无法从https://github.com/hui-Zz/RunAnyCtrl上读取最新版本文件 18 | return 19 | } 20 | URLDownloadToFile,%RunAnyGithubDir%/RunAnyCtrl_Update.ahk ,%A_Temp%\temp_RunAnyCtrl_Update.ahk 21 | versionReg=iS)^\t*\s*global RunAnyCtrl_update_version:="([\d\.]*)" 22 | Loop, read, %A_Temp%\temp_RunAnyCtrl_Update.ahk 23 | { 24 | if(RegExMatch(A_LoopReadLine,versionReg)){ 25 | versionStr:=RegExReplace(A_LoopReadLine,versionReg,"$1") 26 | break 27 | } 28 | if(A_LoopReadLine="404: Not Found"){ 29 | MsgBox,"网络异常,下载失败" 30 | return 31 | } 32 | } 33 | if(versionStr){ 34 | if(RunAnyCtrl_update_version