fusion400 Posted March 25, 2010 Share Posted March 25, 2010 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. Link to comment Share on other sites More sharing options...
NerdFencer Posted March 25, 2010 Share Posted March 25, 2010 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 Link to comment Share on other sites More sharing options...
fusion400 Posted March 25, 2010 Author Share Posted March 25, 2010 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. Link to comment Share on other sites More sharing options...
NerdFencer Posted March 25, 2010 Share Posted March 25, 2010 The @hour macro works on a 24 hour clock If you are testing on 6 PM, you need to use 18, not 6 _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell Link to comment Share on other sites More sharing options...
fusion400 Posted March 25, 2010 Author Share Posted March 25, 2010 (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 March 25, 2010 by fusion400 Link to comment Share on other sites More sharing options...
Negative1 Posted March 25, 2010 Share Posted March 25, 2010 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. Link to comment Share on other sites More sharing options...
fusion400 Posted March 25, 2010 Author Share Posted March 25, 2010 (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 March 25, 2010 by fusion400 Link to comment Share on other sites More sharing options...
Negative1 Posted March 25, 2010 Share Posted March 25, 2010 (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 March 25, 2010 by Negative1 What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world. Link to comment Share on other sites More sharing options...
fusion400 Posted March 25, 2010 Author Share Posted March 25, 2010 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:00How is autoit apps debugged how can i see what the hour variable has for value?Works perfectly now.Thanks alot for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now