Problems with Remote Desktop

Ask general questions here.
Posts: 20
Joined: Sat Feb 17, 2018 12:37 am

Problems with Remote Desktop

Post by cpalex » Wed Dec 12, 2018 5:50 pm

We recently got our test machine in our data center set up, but I have been having some issues getting it to work correctly.

First, it appears as if the setting in Ranorex Agent, "Keep Session Active", doesn't actually keep the section active. Running a test after closing the RDP session returns blank screen shots.

My second attempt was to use the old batch file technique from the FAQ: ... emote-faq/

And while that doesn't lock the screen, the screen resolution is changing to 544x600, which is far too small for our AUT.

After some research, it appeared that I simply needed to change the default resolution. So I followed the instructions here: ... forWindows

But the resolution is still being set to 544x600. I went ahead and changed ALL DefaultSettings.XResolution and DefaultSettings.YResolution in my registry to be 1920x1080, but it is still resetting to 544X600.

My current workaround is to disable the lock when RDP is minimized, described here: ... imized-rdc

Which seems to work, for now.

But with the scale we are looking at, I would really like to be able to not have an RDP session active on some machine in order to run tests.

So, question one, is there a reason the "Keep Session Active" may not be working?

And even if I get that working, I have a feeling I'll run into question number two, how do I set the resolution when using the batch file to keep the session open?

Posts: 4
Joined: Tue Oct 16, 2018 2:52 pm

Re: Problems with Remote Desktop

Post by Tolga » Fri Dec 14, 2018 2:09 pm

We have the same situation. We just fire up a VNC-Connection for every VM and leave the Session to itself.
Obviously you have to disable the Windows Lockscreen if it is Idle for x minutes...
But it works and we do not have to use (unsecure) RDP-Sessions.

If you want to do work on the VM --> go for RDP.
If you want to let the VM work through the agent or jenkins --> go for VNC.

The main problem is: Windows tries to save energy. And there is (i guess) no key in the registry where you can tell Windows: "stop shutting down the GUI no matter what!!!"

User avatar
Posts: 139
Joined: Mon Jul 11, 2016 2:15 pm

Re: Problems with Remote Desktop

Post by Vega » Mon Dec 17, 2018 6:38 am

I have not personally had any issue with the keep session alive feature, so it may be possible that you have a group policy or security solution in place which is force locking the work station. I would recommend using Agent over RDP for execution if possible, as I have had RDP introduce artificial latency in the past which affected my tests among other issues. What happens when you deploy your test to the Agent (unlocked/active user session) but never RDP in?

Posts: 20
Joined: Sat Feb 17, 2018 12:37 am

Re: Problems with Remote Desktop

Post by cpalex » Wed Dec 19, 2018 9:32 pm

Vega wrote:
Mon Dec 17, 2018 6:38 am
What happens when you deploy your test to the Agent (unlocked/active user session) but never RDP in?
It runs the test, but it fails. The returned screen shots are blank, like the user interface was not active.

These are virtual machines, so I have no way to log in without RDP at the moment

User avatar
Posts: 139
Joined: Mon Jul 11, 2016 2:15 pm

Re: Problems with Remote Desktop

Post by Vega » Thu Dec 27, 2018 6:48 pm

Blank screenshots are usually an indicator that the user session is locked as you mentioned. I understand having to RDP into the machine for normal access, but once you have Agent setup you will be able to execute your tests without RDP. If the session is still being locked even with both the Agent setting and the old keep alive script, then I am leaning towards a security policy or application locking the system. I would definitely check with your IT staff to see if this is the case.

Please keep us updated!

Hope this helps

Posts: 2
Joined: Fri Nov 10, 2017 3:31 pm

Re: Problems with Remote Desktop

Post by Suchy » Fri Jan 18, 2019 2:09 pm

I'm running Ranorex tests on TeamCity agent and solved this issue. No active RDP needed to run tests, but you need to cofigure your VM for auto login and keeping the desktop alive.

1. Set your VM to auto-login on whatever account you use to run tests on:
- start regedit and go to: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
- Set: AutoAdminLogon = 1
- Set (or add new String Value, if doesn't exist): DefaultUserName = <domain>\<username>
- Set (or add new): DefaultPassword = <pass>

2. Set screen resolution in Registry:
-go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Video\{<GUID>}\0000, change DefaultSettings.XResolution to 780 (hex) and DefaultSettings.YResolution to 438 - this will set 1920x1080

3. Create a stay-awake PowerShell script and schedule it to start on logon:

Code: Select all

#!/usr/bin/env powershell

# This script can keep the computer awake while executing another executable, or
# if no executable was passed in, then it stays awake until this script stops.
# There are 3 different ways of staying awake:
#     Away Mode - Enable away mode (
#     Display Mode - Keep the display on and don't go to sleep or hibernation
#     System Mode - Don't go to sleep or hibernation
# The default mode is the Display Mode.
# Away mode is only available when away mode is enabled in the advanced power options.
# These commands are advisory, the option to allow programs to request to disable
# sleep or display off is in advanced power options.
# The above options will need to be first enabled in the registry before you can
# see them in the advanced power options.
# An alternative to this script is using presentation mode, but this is more flexible.

param (
    [string]$Executable = $null,
    [ValidateSet('Away', 'Display', 'System')]$Option = 'Display'

[email protected]'
[DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]
public static extern void SetThreadExecutionState(uint esFlags);

$ste = Add-Type -memberDefinition $Code -name System -namespace Win32 -passThru

# Requests that the other EXECUTION_STATE flags set remain in effect until
# SetThreadExecutionState is called again with the ES_CONTINUOUS flag set and
# one of the other EXECUTION_STATE flags cleared.
$ES_CONTINUOUS = [uint32]"0x80000000"
$ES_AWAYMODE_REQUIRED = [uint32]"0x00000040"
$ES_DISPLAY_REQUIRED = [uint32]"0x00000002"
$ES_SYSTEM_REQUIRED = [uint32]"0x00000001"

Switch ($Option) {
    "Away"    {$Setting = $ES_AWAYMODE_REQUIRED}
    "Display" {$Setting = $ES_DISPLAY_REQUIRED}
    "System"  {$Setting = $ES_SYSTEM_REQUIRED}

try {

    Write-Host "Staying Awake with ``${Option}`` Option"

    $ste::SetThreadExecutionState($ES_CONTINUOUS -bor $Setting)

    if ($Executable) {
        Write-Host "Executing Executable"
        & "$Executable"
    } else {
        Read-Host "Enter or Exit to Stop Staying Awake"

} finally {

    Write-Host "Stopping Staying Awake"

Alternatively you can use some existing tools that prevent sleep, like Insomnial. Just be aware that some of these tools work via pressing a virtual key once in a while, this can screw up your test if it fills up a form or something at the moment.

4. Disable Lock Screen: ... ock-screen

5. Reboot and enjoy :)

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

Re: Problems with Remote Desktop

Post by odklizec » Fri Jan 18, 2019 2:17 pm


I would recommend tool called LogonExpert. I'm using it a it works quite well.
You can set it both to auto logon the machine, keep it logged in and unlocked.
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

User avatar
Posts: 210
Joined: Fri Jul 15, 2016 1:35 pm

Re: Problems with Remote Desktop

Post by Stub » Fri Jan 18, 2019 4:36 pm

I also use LogonExpert after receiving a tip about it here. I've linked it to our MSBuild-based build system so we can automate building of the Ranorex solution, unlocking of the desktop, and relocking of the desktop once complete.

Posts: 20
Joined: Sat Feb 17, 2018 12:37 am

Re: Problems with Remote Desktop

Post by cpalex » Tue Jan 22, 2019 3:39 pm

Update with the solution I found for my setup!

I gave up using Remote Desktop. We have a screen connect setup that allowed me to log into our virtual machine like I had a monitor connected.

But the big problem was screen resolution. My VM wouldn't let me set a resolution high enough for my AUT.

So I followed these instructions:

And voila! The remote session stays active, and I get the resolution I need.

Basically, forget RDP. It's too much trouble.