Sign in to follow this  
Followers 0
fusion400

Script for killing and restarting process at a specfic time.

9 posts in this topic

Hi is it possible to make an autoit script that kills and restarts an application at a specific time.

This script should just sit in the background all the time and restart the application at 06:00 in the morning everyday.

Share this post


Link to post
Share on other sites



Yes

It should look something like this...

Look up the documentation for ProcessClose and Run if you need to.

Global $HasRunToday = False
While 1
    If @HOUR==6 And $HasRunToday==False Then
        ProcessClose("Some Process.exe")
        ProcessWaitClose("Some Process.exe")
        Run("Path to the executable to open")
    ElseIf @HOUR > 6 Then
        $HasRunToday = True
    EndIf
    Sleep(5000)
WEnd

_________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell

Share this post


Link to post
Share on other sites

Yes

It should look something like this...

Look up the documentation for ProcessClose and Run if you need to.

Global $HasRunToday = False
While 1
    If @HOUR==6 And $HasRunToday==False Then
        ProcessClose("Some Process.exe")
        ProcessWaitClose("Some Process.exe")
        Run("Path to the executable to open")
    ElseIf @HOUR > 6 Then
        $HasRunToday = True
    EndIf
    Sleep(5000)
WEnd

It does not seem to work i tried with notepad.exe as the process to close

but nothing happens and i set my clock to 05:59:45.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The @hour macro works on a 24 hour clock

If you are testing on 6 PM, you need to use 18, not 6

I am using 24 hour clock but still nothing happens. It does not kill notepad.exe process.

And the script must work everyday not just once.

Does it work for you ?

Global $HasRunToday = False
While 1
    If @HOUR==6 And $HasRunToday==False Then
        ProcessClose("notepad.exe")
        ProcessWaitClose("notepad.exe")
        Run("cmd.exe")
    ElseIf @HOUR > 6 Then
        $HasRunToday = True
    EndIf
    Sleep(5000)
WEnd
Edited by fusion400

Share this post


Link to post
Share on other sites

Global $HasRunToday = False
While 1
    If @HOUR==6 And $HasRunToday==False Then
        ProcessClose("notepad.exe")
        ProcessWaitClose("notepad.exe")
        Run("cmd.exe")
    ElseIf @HOUR > 6 Then
        $HasRunToday = True
    EndIf
    Sleep(5000)
WEnd

Seams like you have a problem with the logic here:

Global $HasRunToday = False
While 1
    If @HOUR==6 And $HasRunToday==False Then
        ProcessClose("notepad.exe")
        ProcessWaitClose("notepad.exe")
        Run("cmd.exe")
        $HasRunToday = True
    ElseIf @HOUR == 0 and @min == 1 Then
        $HasRunToday = False ;reset the day at 12:01am.    
    EndIf
    Sleep(5000)
WEnd

Maybe I'm mistaken but it seams to me your script will fail if the clock is 7:00am or later when it first runs.

Hope this helps,

-1


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Global $HasRunToday = False
While 1
    If @HOUR==6 And $HasRunToday==False Then
        ProcessClose("notepad.exe")
        ProcessWaitClose("notepad.exe")
        Run("cmd.exe")
    ElseIf @HOUR > 6 Then
        $HasRunToday = True
    EndIf
    Sleep(5000)
WEnd

Seams like you have a problem with the logic here:

Global $HasRunToday = False
While 1
    If @HOUR==6 And $HasRunToday==False Then
        ProcessClose("notepad.exe")
        ProcessWaitClose("notepad.exe")
        Run("cmd.exe")
        $HasRunToday = True
    ElseIf @HOUR == 0 and @min == 1 Then
        $HasRunToday = False ;reset the day at 12:01am.    
    EndIf
    Sleep(5000)
WEnd

Maybe I'm mistaken but it seams to me your script will fail if the clock is 7:00am or later when it first runs.

Hope this helps,

-1

Hi i have tried this version also but it still fails for some reason. Notepad is not killed and cmd is not started. I set my clock to 05:59:45. Start the app and wait for the time to come to 06:00:00

How is autoit apps debugged how can i see what the hour variable has for value?

Edited by fusion400

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Global $HasRunToday = False
While 1
    If @HOUR = 6 And $HasRunToday = False Then
        ProcessClose("notepad.exe")
        ProcessWaitClose("notepad.exe")
        Run("cmd.exe")
        $HasRunToday = True
    ElseIf @HOUR = 0 and @min = 1 Then
        $HasRunToday = False ;reset the day at 12:01am.    
    EndIf
    Sleep(5000)
WEnd

Tested works just fine. Not sure why there was double equals signs in the original.

Cheers

-1

Edited by Negative1

What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

Hi i have tried this version also but it still fails for some reason. Notepad is not killed and cmd is not started. I set my clock to 05:59:45. Start the app and wait for the time to come to 06:00:00

How is autoit apps debugged how can i see what the hour variable has for value?

Works perfectly now.

Thanks alot for your help.

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  
Followers 0