Jump to content

Kill application after a predefined time and restart it


neazoi
 Share

Recommended Posts

Hello I have written a little script (using the recorder) to start up an application and click some buttons after start up.

This script works fine for me

#region ---Au3Recorder generated code Start ---
Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)


Run('C:\Program Files\eQSO\PMR-Radio_Server\PMR_Radio_Server.exe')
_WinWaitActivate("eQSO - Conference Server for PMR Radio ","Idle ID Time (Second")
MouseClick("left",695,351,1)
_WinWaitActivate("PMR_Radio_Server","Failed to connect to")
MouseClick("left",193,89,1)
_WinWaitActivate("PMR_Radio_Server","eQSO Monitor Server ")
MouseClick("left",180,125,1)
_WinWaitActivate("eQSO - Conference Server for PMR Radio ","Idle ID Time (Second")
MouseClick("left",738,10,1)

#region --- Internal functions Au3Recorder Start ---
Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc
#endregion --- Internal functions Au3Recorder End ---

#endregion --- Au3Recorder generated code End ---

The problem I have is that my application crashes after an hour or so, so I need to somehow:

1. kill it

2. wait for a few seconds

3. then restart it (using the script above).

I want the above to loop forever

(PS. I use older version of autoit for win2k, just for reference, but I think much of the code from v3 will work on it)

Thanks so much for your help!

Edited by neazoi
Link to comment
Share on other sites

Something like this?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Something like this?

Hm... having the script (that calls the application) run all the time and restart itself after some time would be a nice solution.

However, the application process needs to be killed before the next restart.

How should I kill the process and wait to see if it is killed indeed, in order to restart the script again?

Link to comment
Share on other sites

Killing an application just to restart it is just a work around.
I would try to find and solve the source of this problem. Did you write the application you need to kill yourself?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Killing an application just to restart it is just a work around.
I would try to find and solve the source of this problem. Did you write the application you need to kill yourself?

No I did not.

BTW this silved the problem in a simple matter for me. I just need to call restart script not.

Thank you all for your replies!

#region ---Au3Recorder generated code Start ---
Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)


Local $iPID = Run('C:\Program Files\eQSO\PMR-Radio_Server\PMR_Radio_Server.exe')
_WinWaitActivate("eQSO - Conference Server for PMR Radio ","Idle ID Time (Second")
MouseClick("left",695,351,1)
_WinWaitActivate("PMR_Radio_Server","Failed to connect to")
MouseClick("left",193,89,1)
_WinWaitActivate("PMR_Radio_Server","eQSO Monitor Server ")
MouseClick("left",180,125,1)
_WinWaitActivate("eQSO - Conference Server for PMR Radio ","Idle ID Time (Second")
MouseClick("left",738,10,1)

#region --- Internal functions Au3Recorder Start ---
Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc
#endregion --- Internal functions Au3Recorder End ---
Sleep(30000) ;30sec pause. This is how often to restart the program
ProcessClose($iPID)
#endregion --- Au3Recorder generated code End ---

and the restart function, to be called at the end to the code above

Func RestartScript()
    If @Compiled = 1 Then
        Run( FileGetShortName(@ScriptFullPath))
    Else
        Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
    EndIf
    Exit
EndFunc

 

Edited by neazoi
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...