![如何关闭所有正在运行的脚本并稍后重新启动它们?](https://linux22.com/image/1562900/%E5%A6%82%E4%BD%95%E5%85%B3%E9%97%AD%E6%89%80%E6%9C%89%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%E7%9A%84%E8%84%9A%E6%9C%AC%E5%B9%B6%E7%A8%8D%E5%90%8E%E9%87%8D%E6%96%B0%E5%90%AF%E5%8A%A8%E5%AE%83%E4%BB%AC%EF%BC%9F.png)
为了更新 AutoHotkey,必须关闭所有正在运行的脚本。可以使用一个简单的脚本终止 AutoHotkey 进程(见下文),但我不知道如何随意重新启动相同的进程。目前,我在更新后重新启动计算机(以启动 Windows 启动文件夹中的 AHK 脚本)。
Windows 显然不允许同时启动多个文件。因为我启用了几十个 AutoHotkey 脚本,所以手动启动它们是不可行的。
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Loop
{
#Singleinstance force
Process, Close, Autohotkey.exe
}
答案1
; FileDelete, %A_Desktop%\my running scripts.ini
; Get a list of all running AHK scripts:
DetectHiddenWindows, ON
WinGet, id, list, ahk_class AutoHotkey
Loop, %id% ; retrieves the ID of the specified windows, one at a time
{
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
SkriptPath := RegExReplace(title, " - AutoHotkey v" A_AhkVersion )
If InStr(SkriptPath, A_ScriptFullPath)
continue
; Store the path of each running script in an INI-file and terminate it:
IniWrite, %SkriptPath%`n, %A_Desktop%\my running scripts.ini, my_running_scripts
WinClose, %SkriptPath% ahk_class AutoHotkey
}
; Run %A_Desktop%\my running scripts.ini
; Create a new script in the startup folder that starts the same scripts after rebooting:
FileAppend,
(
IniRead, my_running_scripts, `%A_Desktop`%\my running scripts.ini, my_running_scripts
Loop, parse, my_running_scripts, ``n
Run `%A_LoopField`%
; FileDelete, `%A_ScriptFullPath`%
ExitApp
)
, %A_Startup%\my running scripts.ahk
ExitApp
return
如果您想从桌面手动重新启动脚本,请替换%A_Startup%
为。%A_Desktop%