neazoi

Kill application after a predefined time and restart it

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Something like this?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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?

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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