Mian

Script not executing when added to scheduled task

7 posts in this topic

#1 ·  Posted (edited)

#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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

ok trying :), but if the window is not appearing then how controlsend will work?

 

 

Edited by Mian

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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")

 

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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it
    • Nareshm
      By Nareshm
      Please Somebody Help me i am trying to create new script but, i don't know how to create it.

      I am Creating script like this :
      ; My script here [First Script]
      Check the internet connection, if internet connected then
      ; My Script here [Second Script]
      If internet not connected, wait for connect, after connected run my second script
      If Control id/windows/title matched do nothing and end/exit autoit script
      If Control id/windows/title not matched repeat my first and second script again until control id/windows/tittle not matched

      match with :
      >>>> Window <<<<
      Title:    PS :: Version - 2.8.0.0  - [PS Bill]
      Class:    WindowsForm734a
      Position:    -8, -8
      Size:    1382, 744
      Style:    0x17CD0000
      ExStyle:    0x00050100
      Handle:    0x0000000000130572
      >>>> Control <<<<
      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
       
    • kawliga751
      By kawliga751
      I am attempting to run an Autoit.exe with schtasks every weekday @ 9:05 am.
      I have the below
      C:\>SchTasks /Create /TN "P10Run" /TR "O:\AUTOIT\P40 Run.au3" /SC WEEKLY /D MON, TUE,WED,THU,FRI /ST 09:05:00 SUCCESS: The scheduled task "P10Run" has successfully been created. I also did a "test" run :
      C:\>Schtasks /Run /TN "P10Run SUCCESS: Attempted to run the scheduled task "P10Run". But when I run my query to verify success my "Last Result" seems to indicate that the script did not run:
      C:\>SCHTASKS /QUERY /FO LIST /V /TN "P10RUN" Folder: \ HostName: xxxxxxxxxxxxxxxx TaskName: \P10RUN Next Run Time: N/A Status: Could not start Logon Mode: Interactive only Last Run Time: 6/14/2017 9:08:56 AM Last Result: -2147024894 Author: xxxxxxx Task To Run: O:\AUTOIT\P40 Run.au3 Start In: N/A Comment: N/A Scheduled Task State: Enabled Idle Time: Disabled Power Management: Stop On Battery Mode, No Start On Batterie s Run As User: xxxxxxxxx\xxxxxxxx Delete Task If Not Rescheduled: Enabled Stop Task If Runs X Hours and X Mins: 72:00:00 Schedule: Scheduling data is not available in this f ormat. Schedule Type: Weekly Start Time: 9:05:00 AM Start Date: 6/14/2017 End Date: N/A Days: MON, TUE, WED, THU, FRI Months: Every 1 week(s) Repeat: Every: Disabled Repeat: Until: Time: Disabled Repeat: Until: Duration: Disabled Repeat: Stop If Still Running: Disabled C:\> Is there something missing in my command? Also is there a better way to make sure that the script does in fact sun successfully?
      Thanks In Advance! 
    • chacoya121
      By chacoya121
      please help, how to write script for multiple choice question
      in GUI
      -single program
      -add more question to program
      example:
      1. this is the question
      a. answer a
      b. answer b
      c. answer c
      d.answer d
      - 300 questions +  700 answers
      please give me some tips to create a script
      read and write file from notepad, that mean u need notepad attach?
       
       
    • Meobdg
      By Meobdg
      Hi, I have a problem, my functions do not work with each other. Separately, each works very well. Features that do not work together it's loot() and  pos1(). It looks that after spreadsheet function loot() script stops working even though everything is in the While 1-Wend loop.  Can someone help me please?