Jump to content

Run my script at a particular time


Recommended Posts

I wrote the following script to reboot my modem.
Now i want to ensure that if the script is running then the following actions only take place after 7.00 pm.
I tried Windows Tasker but it wasn't the right choice for me.
I tried to use Time Macros but cannot seem to use it properly.

NOTE - I have no coding experience so please try to explain the answer.

#include <IE.au3>
#include <AutoItConstants.au3>

If ProcessExists("uTorrent.exe") Then
   ProcessClose("utorrent.exe")
EndIf
Local $oIE, $oUN
$oIE = _IECreate("192.168.1.1")
_IELoadWait($oIE)
$oUN = _IEGetObjById($oIE, "unLi")
Send("USERNAME")
Sleep(4000)
Send("{TAB}")
Send("PASSWORD")
Send("{ENTER}")
Send("{RWINDOWN}")
Send("{UP}")
Send("{RWINUP}")
Sleep(10000)
MouseClick("left",68,376)
Sleep(2000)
MouseClick("left",67,570)
Sleep(6000)
MouseClick("left",791,328)
Sleep(1000)
Send("{ENTER}")
Sleep(105000)
If ProcessExists("iexplore.exe") Then
   ProcessClose("iexplore.exe")
EndIf
Sleep(1000)
Run("C:\Users\User\AppData\Roaming\uTorrent\uTorrent.exe")

 

Link to comment
Share on other sites

Have you tried Windows Task Scheduler and starting your script at 7:00pm? I don't know what "Windows Tasker" is. If what you mean is Windows Task Scheduler, is your PC set to lock windows after a certain amount of time? 

Are you saying you tried rebooting your modem at 7pm using windows task scheduler or tried running your script using task scheduler? 

 

Your script is using active windows it looks like and if your screen is locked when the script starts then it will pretty much fail. 

 

Does your script work when the PC is unlocked and not in sleep mode?

Edited by RickB75
Link to comment
Share on other sites

Yeah I meant windows task scheduler and it works but you can only program it for pre defined time like daily, weekly, and so on. 

I tried running my script using task scheduler. But I want to customize it like it should only work if I run it and then wait until 7pm to execute the commands

Link to comment
Share on other sites

What is the model number and manufacturer of your modem?  It may be easier to send commands directly to the modem to reboot it, without using an user interface at all.  This would make scheduling the reboot easier.  

 

Adam

 

Link to comment
Share on other sites

So you want to run the program at say, 2pm - but it won't do anything until 7pm?  And if you run it at 10pm it should just run?  I thought I had a more elegant solution, but this should work...

#include <Date.au3>
$HourToReboot = 19 ; the hour you want router to be reset

If StringLeft(_NowTime(4),2) < $HourToReboot Then
    Do
        Sleep(60000) ; wait a minute
    Until StringLeft(_NowTime(4),2) >= $HourToReboot
EndIf

MsgBox (0,"","Rest of your program will run here at or after the specified hour") 

 

Edited by MuffinMan
Fixed variable error spotted by RickB75
Link to comment
Share on other sites

I follow you now @tatoo236. @MuffinMan has a good example you can implement. You needed to add a loop into your script. What the example is doing is in loop and sleeping for 1 min until the magic hour of 7pm or 19:00. If you look in the help file, you will see that the _nowTime function with a paramater of 4 is converting the result to a 24hr format.  In the example, make sure to change $TimeToReboot to $HourToReboot in the 'IF' statement.  Just make sure to put MuffinMan's  script above yours like below. Also, comment out the MsgBox or set a time option like this

MsgBox (0,"","Rest of your program will run here at or after the specified hour",5)

 The MsgBox above will timeout after 5 seconds. 

#include <IE.au3>
#include <AutoItConstants.au3>
#include <Date.au3>
$HourToReboot = 19 ; the hour you want router to be reset

If StringLeft(_NowTime(4),2) < $HourToReboot Then
    Do
        Sleep(60000) ; wait a minute
    Until StringLeft(_NowTime(4),2) >= $HourToReboot
EndIf

MsgBox (0,"","Rest of your program will run here at or after the specified hour") 
If ProcessExists("uTorrent.exe") Then
   ProcessClose("utorrent.exe")
EndIf
Local $oIE, $oUN
$oIE = _IECreate("192.168.1.1")
_IELoadWait($oIE)
$oUN = _IEGetObjById($oIE, "unLi")
Send("USERNAME")
Sleep(4000)
Send("{TAB}")
Send("PASSWORD")
Send("{ENTER}")
Send("{RWINDOWN}")
Send("{UP}")
Send("{RWINUP}")
Sleep(10000)
MouseClick("left",68,376)
Sleep(2000)
MouseClick("left",67,570)
Sleep(6000)
MouseClick("left",791,328)
Sleep(1000)
Send("{ENTER}")
Sleep(105000)
If ProcessExists("iexplore.exe") Then
   ProcessClose("iexplore.exe")
EndIf
Sleep(1000)
Run("C:\Users\User\AppData\Roaming\uTorrent\uTorrent.exe")

 

Link to comment
Share on other sites

I looked at the user manual - this modem does not support command line. It only will use the web interface out of the box. Saying that, you may want to look at this:

https://wiki.openwrt.org/toh/tp-link/td-w8960n

You could replace the firmware and then have the modem support command line which will allow for you to reboot with a simple command

Link to comment
Share on other sites

From the user's guide, it looks like there is a reboot option under  “Management”->“Reboot.”  From the reboot page, there is a reboot button.  Look at the source of that page to see what the reboot button actions.  You then may be able to send the router HTTP commands directly using the WinHttp UDF.  I looked in my script library, and was able to find a reboot script that did this with a LINKSYS router.  

 

Adam
 

Link to comment
Share on other sites

Any chance that your computer will be locked at reboot time?  I haven't confirmed but I think generic Send function doesn't work in locked session. 

I would use something like  _IEFormSubmit and _IELinkClickByText instead.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...