Jump to content

Script not executing when added to scheduled task


Mian
 Share

Recommended Posts

#include <Excel.au3>
#include <Array.au3>
#include <String.au3>
#include <IE.au3>


local $oIE =_IECreate ("https://example.com/export")
sleep(5000)
WinWait("Internet Explorer")
WinActivate("Internet Explorer")
send("{TAB 2}")
sleep(1000)
send("{ENTER}")
sleep(1000)
WinWait("Save As")
WinActivate("Save As")
send("PatientsData.csv")
sleep(1000)
send("{TAB 3}")
sleep(1000)
send("{ENTER}")
sleep(1000)
WinWait("Confirm Save As")
WinActivate("Confirm Save As")
send("{TAB 1}")
sleep(1000)
send("{ENTER}")
WinWait("Blank Page - Internet Explorer")
WinActivate("Blank Page - Internet Explorer")
sleep(1000)
RunWait('taskkill /F /IM "iexplore.exe"')
Exit

 

I have written the above simple script, which open a link and save it to the disk. I execute it and every thing works fine. I scheduled it in windows task and it executed fine. However when I scheduled it and I logged out of the system it stops working. The scheduled start the task.exe. Open the internet explorer send f2 to open the save as dialogue and after that it fails to send the tab. 

Since partial script is execute therefore I think that the problem is not related to permissions. The script stops at second or third line.

 

Edited by Mian
Link to comment
Share on other sites

  • Developers

Send() command don't work when running in the background and you need to use ControlSend()

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok my knowledge was limited in running windows gui tasks from scheduled task. The problem is that desktop goes away when user logout and my script needs desktop to show the window. Since no desktop the script keep waiting.

The easiest solution (until I found another way) I can think of is to automate a remote session at the specific time from my office to the server.

Steps1

Create autoit script to login into the server from 2am to 3am.

Step 2

Schedule it to run every night

Step 3

Scedule the scripts to run between 2:10am to 2:50am.

Step 4

Exit the session.

Link to comment
Share on other sites

Thanks Jos. It worked, you are great. Here is the code if another novice like me get into this problem.

 

#include <Excel.au3>
#include <Array.au3>
#include <String.au3>
#include <IE.au3>


local $oIE =_IECreate ("https://example.com/export")
sleep(5000)
ControlSend("Internet Explorer", "", "", "{TAB}")
ControlSend("Internet Explorer", "", "", "{TAB}")
sleep(1000)
ControlSend("Internet Explorer", "", "", "{ENTER}")
sleep(1000)
ControlSend("Save As", "", "", "PatientsData.csv")
sleep(1000)
ControlSend("Save As", "", "", "{TAB}")
ControlSend("Save As", "", "", "{TAB}")
ControlSend("Save As", "", "", "{TAB}")
sleep(1000)
ControlSend("Save As", "", "", "{ENTER}")
sleep(1000)
ControlSend("Confirm Save As", "", "", "{TAB}")
sleep(1000)
ControlSend("Confirm Save As", "", "", "{ENTER}")
sleep(5000)
RunWait('taskkill /F /IM "iexplore.exe"')
;_IEQuit($oIE)
Exit

 

Edited by Mian
Link to comment
Share on other sites

  • 5 months later...

I would recommend you to have a look at the InetGet function (see https://www.autoitscript.com/autoit3/docs/functions/InetGet.htm)

The code you posted above opens a browser, browses to a URL and then saves the webpage. All of this can be accomplished in 1 line of code without relying on Internet Explorer:

InetGet("https://example.com/export", "PatientsData.csv")

 

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

×
×
  • Create New...