ClosedBy closes a program when a file contains a word.
Batch file,Use a special command to stop the application?Download and install
AutoHotkey to run the script.
Save the script to ClosedBy.ahk and doubleclick to run.
10.07.2017: Added a timeout. Corrected a bug when selecting a file to watch.
Skrommel
;ClosedBy.ahk
; Closes a program when a file contains a word
;Skrommel @ 2017
#NoEnv
#SingleInstance,Force
Gosub,INILOAD
Gosub,GUI
Return
GUI:
;Menu,Tray,NoStandard
Menu,Tray,Add,&ClosedBy,SHOW
Menu,Tray,Add
Menu,Tray,Add,&Show...,SHOW
Menu,Tray,Add,E&xit,EXIT
Menu,Tray,Default,&ClosedBy
Menu,Tray,Tip,ClosedBy
Gui,1:Add,Text,,Program to close:
Gui,1:Add,Edit,XM Y+2 W300 Vprogram,% program
Gui,1:Add,Button,X+5 W50 GPROGRAM,&Browse
Gui,1:Add,Text,XM,File to search:
Gui,1:Add,Edit,XM Y+2 W300 Vfile,% file
Gui,1:Add,Button,X+5 W50 GFILE,&Browse
Gui,1:Add,Text,XM,Word to look for:
Gui,1:Add,Edit,XM Y+2 W300 Vword,% word
Gui,1:Add,Text,XM,Delay between searches:
Gui,1:Add,Edit,XM Y+2 W50 Vdelay Limit4,% delay
Gui,1:Add,UpDown,Range1-9999
Gui,1:Add,Text,X+5 W150,seconds
GuiControl,1:,delay,% delay
Gui,1:Add,Text,XM,Timeout before closing program:
Gui,1:Add,Edit,XM Y+2 W50 Vtimeout Limit4,% delay
Gui,1:Add,UpDown,Range1-9999
Gui,1:Add,Text,X+5 W150,seconds
GuiControl,1:,timeout,% timeout
Gui,1:Add,Button,X+100 W50 GRUN +Default,&Run
Gui,1:Add,StatusBar,GWEBPAGE,1HourSoftware.no
SB_SetIcon("1HourSoftware.ico")
Gui,1:Show,,ClosedBy
Gui,2:+AlwaysOnTop
Gui,2:Add,Progress,XM W300 Vcountdown Range0-%timeout%,% timeout
Gui,2:Add,Button,XM W100 +Default GCLOSE,&Close the program
Gui,2:Add,Button,X+5 W50 GABORT,&Abort
Return
RUN:
Gui,Submit
Gosub,INISAVE
Loop
{
abort=0
close=0
Process,Exist,%program%
If ErrorLevel>0
{
FileRead,lines,% file
IfInString,lines,% word
{
Gui,2:Show,NoActivate,ClosedBy
countdown:=timeout
Loop,% timeout
{
If close=1
Break
GuiControl,2:,countdown,% countdown
countdown-=1
Sleep,1000
}
If abort=1
Continue
Process,Close,% program
Gui,2:Hide
}
}
Sleep,% delay*1000
}
Return
CLOSE:
close=1
Gui,2:Hide
Return
ABORT:
abort=1
Gui,2:Hide
Return
PROGRAM:
Gui,1:Submit,NoHide
FileSelectFile,program,3,% program,Select a program,Programs (*.exe)
IfExist,% program
{
SplitPath,program,program
GuiControl,1:,program,% program
}
Return
FILE:
Gui,1:Submit,NoHide
FileSelectFile,file,3,% file,Select a text file,Text files (*.txt)
IfExist,% file
GuiControl,1:,file,% file
Return
SHOW:
Gui,1:Show
Return
INILOAD:
IniRead,program,ClosedBy.ini,Settings,program
IniRead,file,ClosedBy.ini,Settings,file
IniRead,word,ClosedBy.ini,Settings,word
IniRead,delay,ClosedBy.ini,Settings,delay
IniRead,timeout,ClosedBy.ini,Settings,timeout
If program=ERROR
program=Calc.exe
If file=ERROR
file=C:\Output.txt
If word=ERROR
word=FINISHED
If delay=ERROR
delay=10
If timeout=ERROR
timeout=30
Return
INISAVE:
IniWrite,% program,ClosedBy.ini,Settings,program
IniWrite,% file,ClosedBy.ini,Settings,file
IniWrite,% word,ClosedBy.ini,Settings,word
IniWrite,% delay,ClosedBy.ini,Settings,delay
IniWrite,% timeout,ClosedBy.ini,Settings,timeout
Return
WEBPAGE:
Run,http://www.1HourSoftware.no,,UseErrorLevel
Return
GuiClose:
EXIT:
Gosub,INISAVE
ExitApp