Jump to content
Mian

Script not executing when added to scheduled task

Recommended Posts

Mian
#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
Mian

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
Mian

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
Mian

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
lvsteche

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

    • lenclstr746
      By lenclstr746
      Hi guys,
      Some functions of my script are running slowly. Very slow. What is the reason?
      My Code:
      <snip>
    • ergo
      By ergo
      CronToTime.au3 UDF converts a Unix Cron expression into a DateTime string.
      On Unix systems a Cron expression made of five fields separated by blanks/tabs followed by a shell command to execute.

      e.g. 15-30 2,3,4,5 29 1-12 0-6 reboot
      +------------- minute (0 - 59)
      ¦ +------------- hour (0 - 23)
      ¦ ¦ +------------- day of month (1 - 31)
      ¦ ¦ ¦ +------------- month (1 - 12)
      ¦ ¦ ¦ ¦ +------------- day of week (0 - 6) (Sunday to Saturday, 7 is also Sunday)
      ¦ ¦ ¦ ¦ ¦ +------------- some shell command
      ¦ ¦ ¦ ¦ ¦ ¦
      ¦ ¦ ¦ ¦ ¦ ¦
      * * * * * reboot
      (In this UDF the 6th field has no meaning and no influence on the result).
      For more information see https://en.wikipedia.org/wiki/Cron

      Finds the next event of the specified Cron expression, starting from current UTC/GMT.
      _pce_findNextTimeUTC($sCronExp [, $bForwardSearch = True [, $minutesOffset = 0]]])
      Finds the next event of the specified Cron expression. If $sDateTime is not set, local time will be used.
      _pce_findNextTime($sCronExp [, $bForwardSearch = True [, $sDateTime = "" [, $minutesOffset = 0]]])
      Convert names in usable Cron expression values. e.g. "15-30 2,3,4,5 29 July-December Mo-Su" to "15-30 2,3,4,5 29 7-12 1-7"
      _pce_convertNames( $sCronExp )
      See the include for details.
       
      CronToTime_Test.au3
      CronToTime.au3
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • nacerbaaziz
      By nacerbaaziz
      Hello all
      I found this function in the Internet
      It is to play audio files from  the compiled script
      I did not understand just one thing on this function
      func play($name, $wait = 0) local Const $SND_RESOURCE = 0x00040004 local Const $SND_ASYNC = 1 ; Play the file - the script will pause as it sounds if $wait = 0 then DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", BitOR($SND_RESOURCE, $SND_ASYNC)) else DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", $SND_RESOURCE) endIf return 1 endFunc What I did not understand was this variable
      local Const $SND_RESOURCE = 0x00040004 I know that this variable is contains the resource name
      But what if I want to change the name of the resource what i'll do?
      can i do that?
      Thanks in advance
       
    • krasnoshtan
      By krasnoshtan
      Hello forum users!
      At some point I had a need to restart my script. Is it possible to do this with autoit or do I need to connect additional scripts like .cmd or .bat?
      For example: i have only script.au3 and it's running. Wich code shoud i use to exit from the script and start it again?
×