-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoRestartWiresX.ahk
163 lines (145 loc) · 5.17 KB
/
AutoRestartWiresX.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* @file
* @author Terry Ebdon
* @date October 2022
* @brief Script to auto-dismiss Wires-X "Please Reboot" messages
*
* Wires-X will restart itself once the message is dismissed. This script
* restarts the app with minimal delay. All restarts are logged. By default
* messages are logged to the console. This can be changed via the configuration
* file. Multiple consecutive restarts are handled, with a short delay between
* restarts to avoid locking the user out. The Wires-X reboot requests are
* typically hours, even days, apart. Under these circumstances the script's
* response will be almost instantaneous.
*/
/**
* @copyright Terry Ebdon, 2022
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#SingleInstance, Force
SendMode Input
SetWorkingDir, %A_ScriptDir%
#Include %A_ScriptDir%
#Include, Config.ahk
logScriptVersion()
logSystemDetails()
logMessage( "Trigger title: " . wiresxMsgboxTitle )
logMessage( "Trigger exe: " . exeName )
logMessage( "Trigger text: " . wiresxMsgboxTriggerText )
DetectHiddenWindows, On ; Interact with pop-up when it's behind another window
Loop {
logMessage( "Waiting for a WIRES-X restart request." )
WinWait, %wiresxMsgboxTitle% ahk_exe %exeName%,%wiresxMsgboxTriggerText%
logWiresxRestartRequest()
WinActivate, %wiresxMsgboxTitle% ahk_exe %exeName%,%wiresxMsgboxTriggerText%
SendInput {Space}
infiniteLoopBreaker()
}
/* Prevent user lock-outs by sleeping between events.
* If Wires-X continually dismally restart requests it's
* possible that the AHK / Wires-X interaction could Lock
* the user out. To avoid this the script sleeps after dismissing the
* Wires-X restart request. The sleep time is the sum of the
* minTimeBetweenRestartsMins configuration value (in minutes) and a
* hard-coded 15 seconds. The hard-coded value is a safety delay,
* in case of configuration errors.
*/
infiniteLoopBreaker() {
global minTimeBetweenRestartsMins
static sleepTime := minTimeBetweenRestartsMins * 60 * 1000
logMessage( "Sleeping for "
. minTimeBetweenRestartsMins . " minutes" )
Sleep, %sleepTime%
logMessage( "Almost awake" )
Sleep, 15000 ; Back stop, in case of misconfiguration.
}
getLogFileName() {
global logFile
global logNamePrefixTimeStampFmt
if ( logFile != "*" ) {
SplitPath, logFile, logFileName, logDir,,,
if !FileExist( logDir ) {
FileCreateDir, %logDir%
}
FormatTime, timeStamp,, %logNamePrefixTimeStampFmt%
rollingLogFileName := logDir . "\" timeStamp . "_" . logFileName
} else {
rollingLogFileName = "*"
}
return rollingLogFileName
}
logSystemDetails() {
if ( A_Is64bitOS ) {
osWordSize = 64
} else {
osWordSize = 32
}
logMessage( "v-- OS Details --v")
logMessage( "OS Version: " . A_OSVersion )
logMessage( "OS word size: " . osWordSize )
logMessage( "Pointer size: " . A_PtrSize )
logMessage( "Language: " . A_Language )
logMessage( "Computer name: " . A_ComputerName )
logMessage( "Logged in as: " . A_UserName )
logMessage( "Is admin: " . A_IsAdmin )
logMessage( "^-- OS Details --^")
}
logScriptVersion() {
FileGetVersion, ahkVersion, %A_ProgramFiles%\AutoHotkey\AutoHotkey.exe
FileGetSize, scriptSize, %A_ScriptName%, b
FileGetTime, scriptTime, %A_ScriptName%
FormatTime, scriptTimeFormatted, %scriptTime%, yyyy-MM-dd HH:mm:ss
logMessage( "AHK Version: " . ahkVersion )
logMessage( "Script: path: " . A_ScriptFullPath )
logMessage( "Script timestamp: " . scriptTimeFormatted )
logMessage( "Script size: " . scriptSize . " bytes" )
logHashes()
}
logHashes() {
logMessage( "v-- Script Hashes --v")
logHash( A_ScriptName )
logHash( "Config.ahk" )
logMessage( "^-- Script Hashes --^")
}
logHash( file ) {
cmd := "cmd.exe /q /c CertUtil -hashfile " . file
certUtilOutput := ComObjCreate("WScript.Shell").Exec( cmd ).StdOut.ReadAll()
outputArr := ( StrSplit( certUtilOutput, "`r`n" ) )
sha1Hash := outputArr[2]
logMessage( sha1Hash . " " . file )
}
/* Log text from the Wires-X message box
* All non-blank lines will be logged, with one line per log entry.
*/
logWiresxRestartRequest() {
WinGetText, text
Loop, parse, text, `n, `r
{
if ( A_LoopField != "" ) {
logMessage( A_LoopField )
}
}
}
/* Log a message prefixed with a timestamp.
* The timestamp format and log file name are derived from
* the configutation file.
* @param message the string to be logged.
*/
logMessage( message ) {
global logFile
global timeStampFmt
FormatTime, now,, %timeStampFmt%
outMessage := now . " " . message . "`n"
logFilePath := getLogFileName()
FileAppend, % outMessage, %logFilePath% ;
}