Awz Posted January 27, 2017 Share Posted January 27, 2017 Hello, I'm having an issue getting my script to run properly through task scheduler. This is an auto backup\shutdown\restart script using batch files and some send commands for the Minecraft server. All works 100% when I manually execute the script, but in task sheduler the If then commands I've written fail to function and it skips to the end and runs the batch files. expandcollapse popupIf WinExists("C:\Windows\system32\cmd.exe") Then WinActivate("C:\Windows\system32\cmd.exe") Send("say Server will be restarting in 5 minutes. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(60000) Send("say Server will be restarting in 4 minutes. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(60000) Send("say Server will be restarting in 3 minutes. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(60000) Send("say Server will be restarting in 2 minutes. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(60000) Send("say Server will be restarting in 1 minute. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(30000) Send("say Server will be restarting in 30 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(20000) Send("say Server will be restarting in 10 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 9 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 8 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 7 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 6 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 5 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 4 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 3 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 2 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 1 second. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("save-all") Send("{Enter}") Send("say Server is now shutting down and should be up and running again in 30 seconds.") Send("{Enter}") Sleep(5000) Send("stop") Send("{Enter}") Sleep(5000) send("{Enter}") EndIf run("backup.bat") sleep(10000) run("server.bat") Everything inside the If - then does not run. It immediately jumps to the backup.bat and server.bat when ran in task scheduler. In the program\script box i have ("D:\Games\Minecraft Servers\Minecraft Server2\ServerAutoSave.au3") and in the Start in(optionally) field i have (D:\Games\Minecraft Servers\Minecraft Server2\). I've spent 3 hours reading these forums and others and I'm at a 100% loss. On a side note. How would I have a .bat file ran from this script if it is not in the same folder as the script file. Thanks for any assistance anybody can give. I'm tearing my hair out. Link to comment Share on other sites More sharing options...
Awz Posted January 27, 2017 Author Share Posted January 27, 2017 I've just ran some tests this morning. I am able to successfully run the batch files through the task scheduler on their own, without them being told to run by the script. This tells me that the issue seems to lie upon the .au3 file for some reason or another. Do I have something in my coding wrong? Like I said before it runs perfectly when I run it manually. I will try creating a new script file from scratch for a test and see if I can get that to work and do some basic command. Link to comment Share on other sites More sharing options...
Awz Posted January 27, 2017 Author Share Posted January 27, 2017 Well I got it working. I completely rewrote the entire script from scratch and it worked. If anybody wants to compare my before and after and come up with why it didn't work, maybe it will help somebody in the future. Still not sure what I did to fix it though. By the way the winwait and winminimize all were both added to the previous code and still didn't work. the script never ran from the task scheduler until I rewrote it. expandcollapse popupWinMinimizeAll() If Winexists("C:\Windows\system32\cmd.exe") Then WinActivate("C:\Windows\system32\cmd.exe") WinWaitActive("C:\Windows\system32\cmd.exe") Sleep(250) Send("say Server will be restarting in 5 minutes. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(60000) Send("say Server will be restarting in 4 minutes. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(60000) Send("say Server will be restarting in 3 minutes. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(60000) Send("say Server will be restarting in 2 minutes. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(60000) Send("say Server will be restarting in 1 minute. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(30000) Send("say Server will be restarting in 30 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(20000) Send("say Server will be restarting in 10 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 9 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 8 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 7 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 6 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 5 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 4 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 3 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 2 seconds. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("say Server will be restarting in 1 second. Please complete all tasks and disconnect. Failure to do so could corrupt your character's save file. Thank you.") Send("{Enter}") Sleep(1000) Send("save-all") Send("{Enter}") Sleep(1000) Send("stop") Send("{Enter}") Sleep(5000) Send("{Enter}") Endif Run("backup.bat") Sleep(10000) Run("server.bat") 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