Lock Screen in Windows 7, When Running Tests?

Ask general questions here.
Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Lock Screen in Windows 7, When Running Tests?

Post by Fergal » Wed Jun 24, 2015 11:49 am

[Ranorex 5.3.2, Windows 7]

For security reasons, I'd like to have the screen locked on my Windows machine, when running tests overnight. Basically, start test run and then lock screen without interrupting the test run.

Is this possible?

If not, is there another way to password protect access to a Windows 7 computer, when Ranorex tests are running?

Thanks!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Lock Screen in Windows 7, When Running Tests?

Post by odklizec » Wed Jun 24, 2015 11:57 am

Hi,

No, I don't think you can do that. Ranorex requires unlocked desktop. I think the only reasonable way to achieve what you want is to setup a virtual machine (on your main computer) and run your tests on this VM. Then you can lock your main desktop. BTW, using virtual machine for running tests has one more advantage. You can still work on your main computer while tests are running on VM ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Lock Screen in Windows 7, When Running Tests?

Post by Fergal » Thu Jun 25, 2015 11:51 am

Thanks for your reply odklizec. I would like to figure out a way of doing it without a VM, will reply back here if I do.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Lock Screen in Windows 7, When Running Tests?

Post by krstcs » Thu Jun 25, 2015 12:14 pm

It depends on what type of testing you are doing.

If you are doing some kind of service or load test where you don't need to interact with a GUI, then it can be done, however there may still be issues and it isn't recommended.


If you are trying to do functional GUI testing, which is what Ranorex is designed for, then NO, you will not be able to do it with the system locked. Windows does not allow any application to have access to the GUI when the system is locked or logged off. Technically there is no GUI, because Windows destroys the desktop while the system is locked (or logged off). This is a security feature.


I would agree with Pavel, you should be using virtual machines for testing as much as possible. The VM can be left unlocked while you lock your system. The VM host software virtualizes the guest's desktop in software, so you still have the VM's desktop even when the host is locked.
Shortcuts usually aren't...

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Lock Screen in Windows 7, When Running Tests?

Post by Fergal » Fri Jul 10, 2015 9:24 am

Thanks krstcs.
krstcs wrote:...If you are trying to do functional GUI testing,...
Yes, that is the type of testing I am doing.

Is there a way to create a recording module that will shut down or lock a windows machine? This module could be included at the end of the test suite, so the machine is locked or shut down at the end of the test run.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Lock Screen in Windows 7, When Running Tests?

Post by odklizec » Fri Jul 10, 2015 9:45 am

Hi,

Sure, almost anything is possible (except testing GUI with locked screen ;)). Check for example this sample:
http://www.codeproject.com/Tips/480049/ ... e-or-Sleep

I think you will have to call the "lock/shutdown" code as a very last operation in program.cs (just before return error; line).

Another option (without coding anything) could be setting up a continuous integration environment with slaves machines, that will turn "on" when you start the test, and automatically turn "off" at the end of test. Jenkins CI is particualrly good and free solution, but yes, it requires some time to setup and learn things. But then it's a very helpful and valuable tool for automatized testing.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Lock Screen in Windows 7, When Running Tests?

Post by krstcs » Mon Jul 13, 2015 4:00 pm

Don't use 'Shutdown'. Just lock the system. You can run a batch file as the last module in Ranorex that runs the lock command in Windows:

Code: Select all

rundll32.exe user32.dll,LockWorkStation

'Shutdown' might force the test to end before it full completes.
Shortcuts usually aren't...

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Lock Screen in Windows 7, When Running Tests?

Post by Fergal » Tue Jul 14, 2015 3:52 pm

Thanks odklizec and krstcs.

krstcs is there a way to lock the system with a recording module? If not, were you suggesting that I create a code module using the line of code you provided?

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Lock Screen in Windows 7, When Running Tests?

Post by krstcs » Tue Jul 14, 2015 5:09 pm

The line of 'code' I posted is actually the Windows command-line command that does it.

The only thing you should need to do is to add the "Start Application" action to your module with that command ("rundll32.exe") and the given arguments ("user32.dll,LockWorkStation").
Shortcuts usually aren't...

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Lock Screen in Windows 7, When Running Tests?

Post by Fergal » Wed Jul 15, 2015 1:09 pm

Thank you very much krstcs, that works perfectly.

pstuners
Posts: 1
Joined: Thu Jul 16, 2015 8:10 pm
Location: Phoenix, AZ
Contact:

Re: Lock Screen in Windows 7, When Running Tests?

Post by pstuners » Thu Jul 16, 2015 9:52 pm

You can implement this as a windows task scheduled to be performed at login:

Run program rundll32.exe With arguments user32.dll,LockWorkStation

one (not very best) way to implement it might be:

autologin as passwordless single user
set user password - net user <user> <password>
lock the screen - rundll32.exe user32.dll,LockWorkStation
these two lines can be put into autoexec.bat file or startup folder in a batch file to run on every login

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Lock Screen in Windows 7, When Running Tests?

Post by krstcs » Fri Jul 17, 2015 1:41 pm

I actually use a tool called Autologon, which allows me to remotely lock/unlock and logon/logoff from any system with it installed. Of course it is only installed on test VMs that are deep inside our network... :D

All I have to do is add the unlock command to the start of my test (or, in my case, the start of the Jenkins job) and then add the lock command at the end.
Shortcuts usually aren't...