Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • November 21, 2017, 05:07 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Batch file,Use a special command to stop the application?  (Read 1205 times)

johnny09033

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Use a special command to stop the application?
Its about AlwaysUP application and i use it to run other tools As System, i would like to STOP IT only when the Output.txt content finds the word  FINISHED.

http://imgur.com/a/4sy7f

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,055
    • View Profile
    • Donate to Member
Re: Batch file,Use a special command to stop the application?
« Reply #1 on: May 31, 2017, 01:46 PM »
And you are asking here, instead of at the Core Technologies support-site, because....?
Seems like a decent feature request to me.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 8,999
    • View Profile
    • Donate to Member
Re: Batch file,Use a special command to stop the application?
« Reply #2 on: May 31, 2017, 02:13 PM »
And you are asking here, instead of at the Core Technologies support-site, because....?
Seems like a decent feature request to me.

It seems pretty straightforward that he's asking for a coding snack to remove it because at the site, they might not make it a priority, unless I'm missing something?

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 932
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: Batch file,Use a special command to stop the application?
« Reply #3 on: July 08, 2017, 04:36 PM »
ClosedBy closes a program when a file contains a word. :)

ClosedBy.jpgBatch 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
« Last Edit: July 09, 2017, 05:58 PM by skrommel »

johnny09033

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Batch file,Use a special command to stop the application?
« Reply #4 on: July 09, 2017, 06:54 AM »
thank you !!!