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

    • 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?
    • tintin92
      By tintin92
      Hello,

      How can I automatically download a list of zip files, like the ones in the quote, using a AutoIt script?
      Is it possible with AutoIt script?
       
    • ur
      By ur
      I have an aws cloud machine where I kept all the build process to create some set of zip files and uploading them to OneDrive.
      Once it is completed, I have another local machine in our environment which is a acting as a local share server also.
      Is there anyway to notify this machine(without public IP) to start downloading these files.
      I have written an AutoIT exe to download these files and copy them to respective locations.But don't know how to notify this from the remote machine.
       
      Any suggestion??
       
    • Piotr_Hodl
      By Piotr_Hodl
      Hi guys,
       
      My post is more architecture related than the actual autoit script.
      Currently I have a java tool that makes a connection to a azure Windows VM using WINRM.
      Then I "grep" the session ID of RDP and using psexec I execute my autoit script on the session ID of the RDP (This assumes that I need to have already a RDP connection established).
      The script runs perfectly when I have a RDP session maximized/opened. If I minimize the RDP window some commands do not work, as for example the Send command.
      I do understand that it has to do with the window not being active, even though the script is executed remotely.
      https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F
       
      My goal is to be able to run the autoit scripts with no limitations, like I was running in my local machine.
       
      One important thing, all the flow is being triggered from a linux machine with no GUI. So that is why, I am using a jar file to start the winrm connection.
       
      So to sum up:
      starting server: centos with no GUI
      remote server: azure win 10
      goal: from starting server, launch autoit script that is on remote server
       
      Thanks
      Piotr
       
       
       
×