1

I had written some automation code for our site in which used sikuli for image automation. But sometimes I found that my computer screen locked in between, and that's why many of the test cases failed. So I want to write some python code to keep the screen unlocked.

Here is the code patch which I wrote for locking the screen and now I am searching for how to unlock the screen:

import os

winpath = os.environ["windir"]
os.system(winpath + r'\system32\rundll32 user32.dll, LockWorkStation')

Note: I have already adjusted all the monitor settings which cause screen locking.

pushkin
  • 9,575
  • 15
  • 51
  • 95
reshma
  • 641
  • 1
  • 11
  • 18
  • what this has to be done with Robotframework? – pankaj mishra Dec 29 '17 at 06:11
  • 1
    So you want your program to detect when the computer has locked, so that you can unlock it? Why not just set up your computer so it never locks? How long do the tests take to run? Is it feasible to sit by your computer the entire time? – pushkin Dec 29 '17 at 06:13
  • 1.Yes I want to do it 3.my automation suite takes 20 hrs for execution. 2 I already done with all monitor setting i.e control panel->power options->turn off dispaly -> never and so on.. – reshma Dec 29 '17 at 06:22
  • Even if your computer is locked the processes still runs in the background, untill unless your computer has been put on 'sleep mode' after some time. Check if sleep mode is on!! – pankaj mishra Dec 29 '17 at 06:28
  • Yes processes are running but I need monitor display to match my images on it. When my screen is getting lock images are not match and hence many of the test-cases where failed That's why I need to keep my monitor display on – reshma Dec 29 '17 at 06:34
  • It seems to me that this is not a Robot Framework issue but an issue with Sikuli and locked Windows screens. When looking for those I find the following Stack Overflow answer that might help you. https://stackoverflow.com/questions/26032706/how-to-get-sikuli-working-in-headless-mode – A. Kootstra Dec 29 '17 at 06:49
  • 2
    Simulate user activity to keep the screen active. – Dan D. Dec 29 '17 at 07:15
  • I remember reading an article once how someone solved this by putting a watch with a second-hand underneath the sensor of an optical mouse. Each time the second hand went by, the mouse would register it as movement and thus keep the display open. I thought it was a brilliantly low tech solution. – Bryan Oakley Dec 29 '17 at 14:10
  • thank u guys, actually my company group policy overlaps with my setting n thats why I was failed to screen unlock. But I found one app 'https://downloads.tomsguide.com/Dont-Sleep,0301-28162.html' which solved my issue :) – reshma Jan 04 '18 at 10:22

1 Answers1

1

To work properly Sikuli need UI. This means the user should be logged in. Below are the steps on how to achieve that:

Use Autologon

  1. Download and use Sysinternals Autologon

You should redirect the Console in order to have UI anytime

  1. Create New Task in Task Scheduler
  2. Next in General tab check "Run with highest privileges"
  3. Next in Triggers tab add New trigger
  4. Next in New Trigger dialog select "On disconnect from user session" from "Begin the task" dropdown the press OK with default settings or with the users you will login usually
  5. Create a switch-ui.bat file with the following content in a folder switch-ui on Desktop

echo ################################################### >> %USERPROFILE%\Desktop\rdc_switch_log.log 
date /t >> %USERPROFILE%\Desktop\rdc_switch_log.log time /t >> %USERPROFILE%\Desktop\rdc_switch_log.log 
timeout 3 
query session >> %USERPROFILE%\Desktop\rdc_switch_log.log 
query session > %localappdata%\log.txt

findstr "rdp" %localappdata%\log.txt| findstr "Active" 

if %errorlevel%==0 ( 
    echo You are in RDP session. Do nothing! >>%localappdata%\log.txt 
    ) 
else ( 
    tscon 1 /dest:console 
    tscon 2 /dest:console 
    tscon 3 /dest:console 
    tscon 4 /dest:console 
    )
  1. Next in Actions tab Action
  2. Next in New Action dialog select "Start a program" from Action dropdown
  3. In Settings Program/script add the full path to your file "C:\Users\%yourUsers%\Desktop\switch-ui\switch-ui.bat"
  4. In Start in (optional) add path to your folder with your script "C:\Users\%yourUsers%\Desktop\switch-ui"
  5. Press OK and finish the Task

Important: In order to test that it works.

  1. Get a video recorder
  2. Login on the machine from Remote Desktop Connection (RDC)
  3. Start video
  4. Close RDC
  5. Wait 2 mins
  6. Connect Again
  7. Stop Video
  8. Watch the video

You should have a black video recorded only when you Close RDC and when you connect back with RDC for a few seconds it depends on how fast is your machine.

Assi.NET
  • 432
  • 4
  • 7