Autohotkey 自动热键:如何设置看门狗

Autohotkey 自动热键:如何设置看门狗,autohotkey,Autohotkey,根据事件的不同,我的AHK脚本的预期运行时间介于5分钟到25分钟之间。它主要是从浏览器上抓取屏幕,搜索模式并采取相应的行动(通过点击屏幕上的特定区域)。以及在完成所有操作后终止浏览器会话。我计划在windows任务调度器中每小时运行一次 我的问题是,当有一个网络问题或我的工作站CPU有一个高级的时刻,允许网页加载的时间变得不够(通常大约15秒,它是不可行的,使它更长的内容可能在30秒内改变),或在中间的过程可能挂起。p> 如果发生这种情况,我希望AHK脚本退出,在退出之前,我希望它终止所有浏览器

根据事件的不同,我的AHK脚本的预期运行时间介于5分钟到25分钟之间。它主要是从浏览器上抓取屏幕,搜索模式并采取相应的行动(通过点击屏幕上的特定区域)。以及在完成所有操作后终止浏览器会话。我计划在windows任务调度器中每小时运行一次

我的问题是,当有一个网络问题或我的工作站CPU有一个高级的时刻,允许网页加载的时间变得不够(通常大约15秒,它是不可行的,使它更长的内容可能在30秒内改变),或在中间的过程可能挂起。p> 如果发生这种情况,我希望AHK脚本退出,在退出之前,我希望它终止所有浏览器会话(在这种情况下是chrome)

到目前为止,我还无法想出一个“单一脚本”的解决方案

我目前的状态是启动一个脚本,每30分钟监控一个文件的内容,如果内容与上次没有改变,打开一个新的google chrome会话并发送Shift-Ctrl-Q键序列以关闭所有chrome实例。同时,我的主脚本会在完成时更新同一个文件,其数字与之前的值不同,并且是唯一的。这种方法的缺陷:我不知道如何在不杀死这个看门狗脚本的情况下杀死另一个AHK脚本(挂起的一个)

我的最终愿望是将这个功能构建到主脚本中,它很容易挂起

我的主要剧本

send #r
send chrome.exe http://myURL{enter}
mousemove 200,200
send ^a
send ^c

;
; using a series of IfInString commands
; determine the condition
; then use mousemove, x, y and mouseclick, l
; commands, do my deed 

filedelete, c:\mydir\myfile
fileappend, newnumber, c:\mydir\myfile
exitapp
我的看门狗脚本

loop   ; forever
{
; old content is stored in variable PREV
fileread, newval, c:\mydir\myfile
if (newval = PREV)
{
  send #r
  send chrome.exe
  sleep 10000 ; wait for chrome window to pop up 
  send ^+Q
  ; I need a way to stop my hung AHK script here but don't know how
}
else
{
  PREV = %newval%
  sleep 1800000 ; sleep 30 minutes
}
} ; end of loop
f10::exitapp ; when I need to stop watchdog
当然,这些不是实际的脚本。只是给你一个想法。否则,会有很多页面等待加载等等,但要点就在这里

提前感谢您的帮助

  • 我提供了一些自动热键代码块,可以解决您描述的问题
  • 我会尝试编写两个脚本,这样如果两个脚本都被终止, 这将是可能的做一些检查和恢复,好像什么都没有 已经发生,即增加了更多的灵活性
  • 我个人几乎从未使用过
    SetTimer
    ,我只是在
    Sleep
    中使用循环, 在这种情况下,我认为这无助于改进脚本
  • 我发现,对于挂起的脚本,但对于没有错误消息表示它们已终止的脚本, 您可以检索hWnd(窗口句柄)和PID(进程ID),从而终止它们
  • 使用
    UrlDownloadToFile
    或者
    WinHttpRequest
    (参见论坛上的示例)下载网页,然后解析html
  • 使用Internet Explorer和COM(组件对象模型)可以更容易地完成其他任务, 查询/操作活动网页中的web元素
-

进程看门狗使用: -2台带有共享文件夹的本地PC -3个ahk脚本

PC-1 ahk过程脚本(永远循环) windows启动时自动启动

LOOP   
   put a WD file on PC-2
   run some process
   wait some time 
   go to LOOP
PC-1 ahk WD-1脚本 windows启动时自动启动(永远循环)

PC-2 ahk WD-2脚本 windows启动时自动启动(永远循环)

基本故障场景:

Process script Fails ... PC-1 and PC-2 WD scripts will send emails     
PC-1 Fails ... PC-2 WD script will send email
PC-2 Fails ... PC-1 WD script will send email

改为使用
SetTimer
。我不知道这些脚本的目的是什么,但在我看来,如果您以编程方式提出这些请求,例如使用。就像@JoeDF所说的,将看门狗脚本中的循环改为
SetTimer
,您的生活会轻松得多。
    if initial startup set Counter and put WD file in local shared folder
LOOP 
    wait some time
    if local WD file doesn't exist decrement Counter
    if Counter = Zero Send Email
    if local WD file exists reset Counter and delete local WD file
    go to LOOP
    if initial startup set Counter and put WD file in local shared folder
LOOP 
    wait some time
    if local WD file doesn't exist decrement Counter
    if Counter = Zero Send Email
    if local WD file exists reset Counter and delete local WD File
    put WD file on PC-1 
    go to loop
Process script Fails ... PC-1 and PC-2 WD scripts will send emails     
PC-1 Fails ... PC-2 WD script will send email
PC-2 Fails ... PC-1 WD script will send email