Scheduled Job Doesn't Run Properly When Locked
Moderators: Dorian (MJT support), JRL
-
- Newbie
- Posts: 5
- Joined: Tue Dec 16, 2014 7:31 pm
Scheduled Job Doesn't Run Properly When Locked
I have a script and sub-scripts scheduled to run each morning that log in to a web site and then start a remote desktop session to run a variety of queries and save these to files. The script works fine when I leave the computer logged in and the screen active.
However, when I lock the screen the script starts OK and opens the web site but does not log in to the web site. The script continues through the next steps until it gets to a point where it recognises a screen (some steps on from the web page) is not available and suggests an abort. When I log in to the locked screen I see the web page open to the login page and the Macro Scheduler abort message.
Is there some difference to how Macro Scheduler "sees" the screen or Types when the screen is locked or logged out?
Essentially the steps are:
0. Macro Scheduler wakes up, logs in, does some parameter initiation
1. Open the web browser to the site
2. Wait
3. Set focus on browser window/tab
4. Wait
5. Set position to the Login name box
6. Wait
7. Type login name
8. Tab to password box
9. Wait
10. Type password
11. Press OK
12 Wait
13+ continue with other steps
However, when I lock the screen the script starts OK and opens the web site but does not log in to the web site. The script continues through the next steps until it gets to a point where it recognises a screen (some steps on from the web page) is not available and suggests an abort. When I log in to the locked screen I see the web page open to the login page and the Macro Scheduler abort message.
Is there some difference to how Macro Scheduler "sees" the screen or Types when the screen is locked or logged out?
Essentially the steps are:
0. Macro Scheduler wakes up, logs in, does some parameter initiation
1. Open the web browser to the site
2. Wait
3. Set focus on browser window/tab
4. Wait
5. Set position to the Login name box
6. Wait
7. Type login name
8. Tab to password box
9. Wait
10. Type password
11. Press OK
12 Wait
13+ continue with other steps
-
- Newbie
- Posts: 5
- Joined: Tue Dec 16, 2014 7:31 pm
Re: Scheduled Job Doesn't Run Properly When Locked
I have found that when I run from a locked window I get a second small windows box that has the same window name as the browser window. Consequently when I set focus it chooses this window instead of the browser window.
Not sure what this window is.
How do I distinguish between these so that I can select the browser window?
Not sure what this window is.
How do I distinguish between these so that I can select the browser window?
Re: Scheduled Job Doesn't Run Properly When Locked
Code: Select all
GetWindowHandle>Browser Window Name,BrowserWindowHandle
//Other code
//Next time you need the browser window.
//(It has to have been open this whole time
//or the handle is no longer valid)
Let>WIN_USEHANDLE=1
SetFocus>BrowserWindowHandle
Let>WIN_USEHANDLE=0
-
- Newbie
- Posts: 5
- Joined: Tue Dec 16, 2014 7:31 pm
Re: Scheduled Job Doesn't Run Properly When Locked
Thanks, but which window handle will be returned when both windows have an identical name? I'm guessing the first one again.
I now notice that when I run with the screen unlocked that the same small window box appears briefly after the browser opens but then immediately disappears.
For some reason it does not automatically disappear when the screen is locked, but when I unlock the screen and try to click on the box it disappears.
I have tried to add a LClick into the macro after the SetFocus hoping it would also close the box but that did not seem to do anything.
I now notice that when I run with the screen unlocked that the same small window box appears briefly after the browser opens but then immediately disappears.
For some reason it does not automatically disappear when the screen is locked, but when I unlock the screen and try to click on the box it disappears.
I have tried to add a LClick into the macro after the SetFocus hoping it would also close the box but that did not seem to do anything.
Re: Scheduled Job Doesn't Run Properly When Locked
Sorry. I was assuming the browser window was open before the screen was locked. Re-reading your first post, it would appear that the script starts while the screen is locked and also calls the app that opens the browser window. Is that correct?
You might need to do image or text recognition to determine if the correct window has focus.
The technique would be to get all available top level window handles using GetwindowList> while WIN_USEHANDLE is set to 1. Then cycle through the list of handles setting focus on each window in the list until an image or text is recognized indicating the proper window has focus.
Hopefully this makes sense. If not I'll post a sample tomorrow.
You might need to do image or text recognition to determine if the correct window has focus.
The technique would be to get all available top level window handles using GetwindowList> while WIN_USEHANDLE is set to 1. Then cycle through the list of handles setting focus on each window in the list until an image or text is recognized indicating the proper window has focus.
Hopefully this makes sense. If not I'll post a sample tomorrow.
-
- Newbie
- Posts: 5
- Joined: Tue Dec 16, 2014 7:31 pm
Re: Scheduled Job Doesn't Run Properly When Locked
I have changed the script to use image recognition, which works OK from the scheduler when the screen is left active.
Strangely, when the screen is locked it still did not log into the web page correctly, but the smaller box was gone.
Unfortunately when the job runs it does not unlock the actual screen so I can see what is happening.
The log just tells me commands that started and finished in the last sub-script.
Strangely, when the screen is locked it still did not log into the web page correctly, but the smaller box was gone.
Unfortunately when the job runs it does not unlock the actual screen so I can see what is happening.
The log just tells me commands that started and finished in the last sub-script.
Re: Scheduled Job Doesn't Run Properly When Locked
Does this help?Unfortunately when the job runs it does not unlock the actual screen so I can see what is happening.
https://www.mjtnet.com/blog/2012/06/21/ ... ogged-out/
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Scheduled Job Doesn't Run Properly When Locked
When you lock Windows *THERE IS NO UI*. UI Elements - windows - *cease to exist* and *are not created*. So image recognition or anything that needs to "see" a window or interact with them simply will not be able to. There's nothing we can do about this as it is the way Windows works.
Processes may continue to exist but their UI disappears. There is none. No windows or objects exist. So nothing to interact with.
So the only answer is NOT to lock Windows, OR to use AutoLogon to have Windows unlocked on schedule.
See:
http://help.mjtnet.com/article/29-can-i ... -is-locked
http://help.mjtnet.com/article/14-why-d ... logged-out
http://help.mjtnet.com/article/30-why-d ... es-session
Processes may continue to exist but their UI disappears. There is none. No windows or objects exist. So nothing to interact with.
So the only answer is NOT to lock Windows, OR to use AutoLogon to have Windows unlocked on schedule.
See:
http://help.mjtnet.com/article/29-can-i ... -is-locked
http://help.mjtnet.com/article/14-why-d ... logged-out
http://help.mjtnet.com/article/30-why-d ... es-session
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 5
- Joined: Tue Dec 16, 2014 7:31 pm
Re: Scheduled Job Doesn't Run Properly When Locked
I have autologon set but it does not unlock the window.
Should the computer be logged out for autologon to function correctly?
Should the computer be logged out for autologon to function correctly?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Scheduled Job Doesn't Run Properly When Locked
Locked or Logged out. Also make sure the AutoLogon service is installed (run CRAutoLogon.exe which is in the program folder to install) and start with just locking the workstation while leaving Macro Scheduler running.
This will be useful:
http://help.mjtnet.com/article/49-insta ... -autologon
This will be useful:
http://help.mjtnet.com/article/49-insta ... -autologon
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?