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

    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help
    • ur
      By ur
      With  ProcessList ( ["name"] )  we are able to get the running process list from the local machine.
       
      Is there anyway to get the list from Remote machine, more precisely to get to know the status whether a particular application is running or not on remote machine using AutoIT?
       
      We can implement through PSList.exe, but again we need to parse the text of it to read the output.
      Is there any direct UDF in AutoIT?
    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'
       
    • 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