Jump to content

Recommended Posts

Posted

Have this AutoIT script used to click a button in Web to export data to Excel. It works well when run it from command line or AutoIT compiled .exe.

But after added it to a Win10 VM Task Scheduler as I need to run it daily, it fails to be executed.

Steps to reproduce:

1. Compile the script to .exe.

2. Go to Task Scheduler. Create the task to run this .exe.

3. Right click on the created task -> run  -> shows nothing.

 

Snippet of the code:

Local $URL = "URL"
Local $title = "title"
Local $name = "name"
Local $oIE = _IECreate()

   _IEPropertySet($oIE, "toolbar", False )
   _IEPropertySet($oIE, "height", 800 )
   _IEPropertySet($oIE, "width", 1000 )
   _IEPropertySet($oIE, "left", 0 )
   _IEPropertySet($oIE, "top", 0 )
   _IEPropertySet($oIE, "resizable", False )
   _IENavigate($oIE, $URL)
   Sleep(5000)

   _IENavigate($oIE, $ReportWeb)
   Sleep(10000)
;click the button to export the Excel and save it
ControlClick($titleName, $textName, "[CLASS:Internet Explorer_Server; INSTANCE:1]","main",1,100,100)
ControlSend($title,$name,"[CLASS:DirectUIHWND; INSTANCE:1]","{ENTER}")
Posted
ControlClick

and such functions dont work well from TaskScheduler. Can you change that to IE functions? Also it is very important how you schedule the task to run. Is it running on system account? Does it run with admin rights , is the VM locked or not and so on.

Posted

If you want to use TaskScheduler I sugest to use winhttp.au3 instead ie.au3

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/7/2018 at 7:01 AM, Juvigy said:
ControlClick

and such functions dont work well from TaskScheduler. Can you change that to IE functions? Also it is very important how you schedule the task to run. Is it running on system account? Does it run with admin rights , is the VM locked or not and so on.

Expand  

Thanks for your reply, I found the problem is the scheduled script only runs correctly when i choose "Run only when user is logged on" in Task Scheduler, but I need to run this on daily basis without user log on. Do you have any idea what can be done in the script to resolve this problem?

Posted
  On 8/13/2018 at 12:50 AM, hotkidd said:

Thanks for your reply, I found the problem is the scheduled script only runs correctly when i choose "Run only when user is logged on" in Task Scheduler, but I need to run this on daily basis without user log on. Do you have any idea what can be done in the script to resolve this problem?

Expand  

You can run the script from the 'system' account but depending on the script - it is difficult task....

Posted

@hotkidd, your script relies heavily on the desktop being displayed and windows being interactive - which is typically not the case when running a scheduled task under the local system account. your options are either to have the user constantly logged-on (and schedule the task to run in the user context, not the local SYSTEM account), or rewrite your script as a headless process (either by direct HTTP calls or using another web automation technology, e.g. WebDriver).

 

Signature - my forum contributions:

  Reveal hidden contents

 

Posted

As orbs suggests = you will need to rewrite your script and replace all UI dependent functions like controlclicks and IE.

Posted

@orbs, I actually took over this script from someone who left and claimed it could run from a Win7 VM without user logged on. However, when i tested in on a new Win7 VM, it never runs correctly without user logged on...

do you have any examples of how to rewrite the script as headless process?

Posted

Hi All, this is resolved.

After some research, the solution is to choose "Configure for: Windows Server 2003, Windows XP or Windows 2000" in the Task Scheduler. With this option and choose "Run whether user is logged on or not", GUI related AutoIT script is able to execute without user logged on.

Hope this helps if someone faces the same issue.

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
×
×
  • Create New...