Sign in to follow this  
Followers 0
fuzzie

Script Won't Run As Scheduled Task

23 posts in this topic

I have a script to print about 20 webpages that works if I run it on the desktop.

When I set it up as a scheduled task, it does not complete.

Here is a snippet for one page:

 

_IENavigate($oIE, "https://pageone.html") 

Sleep(5000)
Send("{F5}") ;refresh data
Sleep(5000)
_IEAction ( $oIE, "print" )
Sleep(5000); 5 seconds
 
Send("!g") ; Pages
Send("1-3")
 
Send("!a") ;Apply
Sleep(4000)
 
Send("!p")
Sleep(4000)

 

I'm pretty sure the "Send" commands is what is causing the issue.

But when I try ControlSend("!a") or any other ControlSend, it errors.

Share this post


Link to post
Share on other sites



It might be the !. Try this instead:

_IENavigate($oIE, "https://pageone.html") 
Sleep(5000)
Send("{F5}") ;refresh data
Sleep(5000)
_IEAction ( $oIE, "print" )
Sleep(5000); 5 seconds
 
Send("{!}g") ; Pages
Send("1-3")
 
Send("{!}a") ;Apply
Sleep(4000)
 
Send("{!}p")
Sleep(4000)

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#Include <IE.au3>
HotKeySet("{PAUSE}","TogglePause")
HotKeySet("{ESC}","Terminate")
Global $Paused

Global $oIE = _IECreate("www.google.com")
$HWND = _IEPropertyGet($oIE,"hwnd")
WinSetState($HWND,"",@SW_MINIMIZE)
Sleep(1000)

While 1
    ControlSend($HWND,"","[Class:Internet Explorer_Server]","1")
    Sleep(500)
WEnd

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip("Script is paused",0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

When you use control send you need to specify the control id for the window. The above works. See if you can make it work for whatever you are doing.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

I have a script to print about 20 webpages that works if I run it on the desktop.

When I set it up as a scheduled task, it does not complete.

 

IMHO, this is a bit too vague of a description. I've just been working with scheduled tasks, maybe I can help.

 

I'm pretty sure the "Send" commands is what is causing the issue.

Why? When you're trying to solve a problem on the basis of assumptions, you run the risk of your assumptions being in the way of a proper diagnosis..

Share this post


Link to post
Share on other sites

 

Why? When you're trying to solve a problem on the basis of assumptions, you run the risk of your assumptions being in the way of a proper diagnosis..

I assume the use of Send would be the problem also. The reason is send ONLY works if the control is active the moment Send is used to send text. If it is NOT active then send won't put the string in the right place and if a control that is active can't accept text then nothing happens.

In the OP's script the first line is IENavigate. If IE is NOT open and active the script fails. If the screen is locked then the script fails.

ControlSend will not work on web pages. You have to use the IE controls AND the screen has to accessible with no screensaver running nor the system locked.

Personally having a scheduled task that involves a web page being automated is a real bad idea.

Share this post


Link to post
Share on other sites

 

It might be the !. Try this instead:

_IENavigate($oIE, "https://pageone.html") 
Sleep(5000)
Send("{F5}") ;refresh data
Sleep(5000)
_IEAction ( $oIE, "print" )
Sleep(5000); 5 seconds
 
Send("{!}g") ; Pages
Send("1-3")
 
Send("{!}a") ;Apply
Sleep(4000)
 
Send("{!}p")
Sleep(4000)

Thanks for the suggestion.  I tried that, and it would never send those {} commands.

I'm pretty sure it is because the screen is locked.

Process:

1. Nightly reboot.

2.  Run script at certain time.

3. Repeat daily.

I downloaded AlwaysUp, as an alternative to the task scheduler.  That didn't solve the problem.

If I run it from the script editor or just from Explorer, I watch it work.

I'm most certain it is the Send() commands...I don't think they work in a locked state.  But I don't know how to format ControlSend() or if that is even the right alternative.

Thanks!

Share this post


Link to post
Share on other sites

I assume the use of Send would be the problem also. The reason is send ONLY works if the control is active the moment Send is used to send text. If it is NOT active then send won't put the string in the right place and if a control that is active can't accept text then nothing happens.

In the OP's script the first line is IENavigate. If IE is NOT open and active the script fails. If the screen is locked then the script fails.

ControlSend will not work on web pages. You have to use the IE controls AND the screen has to accessible with no screensaver running nor the system locked.

Personally having a scheduled task that involves a web page being automated is a real bad idea.

I don't doubt it is a bad idea.  

How else do I solve the problem?  I need to log into Yahoo, navigate to about 15 pages, printing each of them, and combine them into one PDF, and email that PDF daily.  I have the script working, just won't run as a scheduled task.

Is there another way?

What if I add:

$hour=17
$minutes=30
$seconds=0
$exit=0
Do
   Sleep(100)
   If $hour=@HOUR And $minutes=@MIN And $seconds=@SEC Then
       $exit=1
   EndIf
Until $exit=1
 
near the top of the script, and put it in the start up folder?  Every nightly reboot, it would start, but not "run" until 5:30 PM.  Would that solve the "locked" issue?

Share this post


Link to post
Share on other sites

But I don't know how to format ControlSend() or if that is even the right alternative.

Thanks!

Example, get handle of your IE

$hwnd = _IEPropertyGet($oIE, "hwnd")

Then

Send("!g") ; Pages

Becomes

ControlSend($hwnd, "", "", "!g") ; Pages

etc...


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Thanks!

Do I need to set this before each ControlSend command?

$hwnd = _IEPropertyGet($oIE, "hwnd")

Or is once enough?  Or maybe once for for each web page?

BTW:  I set up the computer to automatically log the user on, and put the autoit compiled script in the startup folder (and changed the time to execute in the script for testing purposes to something about 15 minutes after rebooting), rebooted the machine.

The script worked!  Testing it again, to see if it was just a fluke!

I think the ControlSend is probably the better route to go.

Was going to try AutoHotKey, but that seemed to have the same background task limitation. 

Do you happen to know of anything else that would do this?  Maybe VBScript or Python?

Thanks!

Share this post


Link to post
Share on other sites

I guess I need it for the FreePDF print dialogue screens too.

How do I find out the name of those windows?

And can I do this:

$hwnd2 = printer dialogue window

Share this post


Link to post
Share on other sites

Why do you need it for that screen? Look in your c:program files x86autoitv3 folder. There is an application called au3info.exe. The program starts "frozen". Click ctrl alt and F to unfreeze it and refreeze it. It will tell you the control id name class etc for a window. Some of these items change when a new instance of it is created. Play with it and see what you come up with.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

That worked perfectly, thanks!

Rather than declare that var again, I just added the title from that program:

ControlSend("FreePDF 4.14", "", "", "!n")

Thanks!

Tested, and it runs as a Scheduled Task now, without hanging up on those print screen dialogues. 

Share this post


Link to post
Share on other sites

Script worked perfectly for 2 weeks.  Yesterday, it failed...all I got was  Error Description Code 1.

Been troubleshooting it and can't tell what happened.  My guess is the "interactive" issue with the desktop running as a scheduled task.  So I tried creating the task with psexec as the command line, with the -i, -u and -p switches set.  Still won't function right.

Am I going down the wrong rabbit hole?

I really don't understand what happened. 

No one uses the computer the script is running on.  It only serves up Plex, besides running this script once a day.

Worked flawlessly for 2 weeks.  Now I can't even get it to work from the autoit program.  It starts, opens IE, logs me into the website and pulls up the page I want printed.  But when the Print command is executed, IE wants to add it to favorites instead.  Very weird!

Share this post


Link to post
Share on other sites

Several times...

So I solved the issue.  Lovely Micro$oft pushed out an update for IE on 12/18...same day script broke.  Stops the Control+P from working in the script.  Don't ask my why or how.  I uninstalled the update and turned automatic updates off.

Like I said, the machine is only used for this function and Plex.  So I am not worried about updates.  Probably not the best or safest solution.  YMMV.

Share this post


Link to post
Share on other sites

This issue has been popping up in more and more applications. Can/could you send ctrl + p with the keyboard but not with a script? What was the name of the update?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

Several times...

So I solved the issue.  Lovely Micro$oft pushed out an update for IE on 12/18...same day script broke.  Stops the Control+P from working in the script.  Don't ask my why or how.  I uninstalled the update and turned automatic updates off.

Like I said, the machine is only used for this function and Plex.  So I am not worried about updates.  Probably not the best or safest solution.  YMMV.

Glad you found out what it was.

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
Sign in to follow this  
Followers 0