Jump to content
Sign in to follow this  
lafafmentvotre

how to restart the program automatically

Recommended Posts

lafafmentvotre

Hi everybody and sorry for my bad english

I want to know how to restart automatically a program who was closed.

I tested the service_create who runs a script. This script must restart a program but i don't know what to insert in this script, like "if my process stops restart this process" with a loop who always running

Thanks for help and the advice

Edited by lafafmentvotre

Share this post


Link to post
Share on other sites
Chimaera

Maybe something like this?

If Not ProcessExists("file to watch.exe Or the PID") Then
sleep(2000)
ShellExecute("file to watch.exe")
EndIf

prob not exactly right but it will get you started.

You will probably need it within a while - wend loop to make it right

Edited by Chimaera

Share this post


Link to post
Share on other sites
lafafmentvotre

Hello

I made this script (that works without error)

#NoTrayIcon
#region AUTOIT VARIABLES
#endregion
#region SCRIPT VARIABLES
Local $bill_process='Bill_Redirect_Serial_to_KB.exe'
Local $win_process='winlogon.exe'
Local $exe='C:\PROGRA~2\BILLPR~1\BILLRE~1\BILL_R~1.EXE'
#endregion
#region SCRIPT
Check_Bill()
#endregion
#region FUNCTIONS
Func Check_Bill()
Do
If ProcessExists($win_process) Then
If ProcessExists($bill_process)=0 Then
ShellExecute($exe)
EndIf
EndIf
Until Not ProcessExists($win_process)
EndFunc
#endregion

And i used this script to create a service who uses this previous script

#region AUTOIT VARIABLES
#include <Services.au3>
#endregion
#region SCRIPT VARIABLES
Local $process='Bill_Redirect_Serial_to_KB.exe'
Local $exe='C:\PROGRA~2\BILLPR~1\BILLRE~1\BILL_R~1.EXE'
Local $sServiceName='BillServices'
Local $sDisplayName='Bill Services'
Local $iServiceType=$SERVICE_WIN32_OWN_PROCESS
Local $iStartType=$SERVICE_AUTO_START
Local $iErrorControl=$SERVICE_ERROR_NORMAL
Local $sBinaryPath='C:\Program Files (x86)\BillProduction\Bill Redirect Serial COM Port to Keyboard Buffer\Bill_Redirect_W7_Services.exe'
#endregion
_Service_Create($sServiceName, $sDisplayName, $iServiceType, $iStartType, $iErrorControl, $sBinaryPath)
;~ _Service_Delete($sServiceName)

But the service doesn't start with Error

Posted Image

Do you have an idea ?

Share this post


Link to post
Share on other sites
lafafmentvotre

Hello

I modified like this

Opt("TrayIconHide", 1)
#region AUTOIT VARIABLES
#endregion
#region SCRIPT VARIABLES
Local $bill_process='Bill_Redirect_Serial_to_KB.exe'
Local $exe='C:\PROGRA~2\BILLPR~1\BILLRE~1\BILL_R~1.EXE'
#endregion
#region SCRIPT
While 1
If ProcessExists($bill_process) Then
Sleep(1000)
ElseIf Not ProcessExists($bill_process) Then
ShellExecute($exe,'')
EndIf
WEnd
#endregion

But my Service doesn't work; I have the same error 1053

Share this post


Link to post
Share on other sites
Bert

Before we go further, why do you need to make sure you have your program restarted if it was closed? I have found in many cases what I refer to as a "Guard" script is usually used for maulware to make sure the maulware stays running. I know there are legit reasons also using the "guard" method to keep an application running but it would be helpful for you to tell us what you have in mind.

Share this post


Link to post
Share on other sites
lafafmentvotre

In fact, my application closes after 30 minutes, and I manage people ask me that this application will not close (hard for them).

I will not put my srcipt as a service, I will add it to the computer startup waiting for something better. This is not a problem too.

In any case thank you for the help on this.

See you soon

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
Sign in to follow this  

×