Can the GUI of an RDP session remain active after disconnect

21,625

Solution 1

This could be a workaround, altough I have not tried it myself and it involves having another machine

Let's assume that at the moment you are creating a session to myserver.com

Local Client ----> myserver.com

Instead of doing that, you could try having a separate server (let's call it myslave.com) and use that to establish a session

Local Client ----> myslave.com ----> myserver.com

Then if you disconnect the Local Client ---> myslave.com session the GUI of the session between myslave.com ----> myserver.com should remain active.

It will work only if you are connected to the console session of myslave.com.

Solution 2

Yes, you can.

There are two types of sessions in Windows: The "console" session which is always active, and there can only be a max of one of, and "terminal" sessions, a la RDP. Using "rdpwrap" on Github, you can have an unlimited number of terminal sessions.

RDP sessions will become "deactivated" when there is not a connection to them. Programs will still run, but anything that depends on GUI interaction will break badly.

Luckily, we may "convert" a terminal session into a console session instead of disconnecting from Remote Desktop normally by running the following command from inside the terminal session:

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (tscon.exe %%s /dest:console)

This will disconnect you from the session, but it will still run with full graphical context. This answers your question. You can reconnect to it and it will become a terminal session again, and you can do this infinitely. And, of course, autohotkey works perfectly.

But, what if you need more than one persistent, graphics-enabled session?

To get an unlimited amount of graphics-persistent sessions, you can run Remote Desktop and start terminal sessions from within the "main" session described above. Normally Remote Desktop prevents this "loopback" behavior, but if you specify "127.0.0.2" for the destination, you will be able to start a terminal session with any number of the users on the remote machine.

The graphics-persistentness will only be present on terminal servers if they are not minimized, unless you create and set RemoteDesktop_SuppressWhenMinimized to 2 at the following registry location:

HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client

With this you can get an unlimited number of completely independent graphics-persistent remote sessions from a single machine.

Solution 3

This could be a workaround, altough I have not tried it myself and it involves having >another machine

Let's assume that at the moment you are creating a session to myserver.com

Local Client ----> myserver.com

Instead of doing that, you could try having a separate server (let's call it myslave.com) and use that to establish a session

Local Client ----> myslave.com ----> myserver.com

Then if you disconnect the Local Client ---> myslave.com session the GUI of the session
between myslave.com ----> myserver.com should remain active

If you are using a windows server you don't even need another machine.

1) Connect to the server with the remote desktop connection (#con1).

2) Create a new alias for your server system like "127.0.0.2" in Windows\System32\drivers\etc\hosts .

3) Now establish a new remote desktop connection from your windows server (in #con1) to itself (#con2).

4) Finally start your GUI needing application e.g. UI-Path in #con2 and then close #con1.

Solution 4

I found a similar way. I had same problem, i downloaded rdp wraper which allows you configure multiple session rpd server and one tool which is included (rdpchecker.exe) allows you connect to localhost so you can connect to your server from your server and you dont need that middle client.

Share:
21,625
user2029890
Author by

user2029890

Updated on January 04, 2022

Comments

  • user2029890
    user2029890 over 2 years

    I'm running automated testing procedures that emulates keystrokes and mouseclicks 24/7.

    Although it runs fine locally, on an RDP session it stops running once minimized or disconnected. Apparently, the GUI doesn't exist if you can't physically see it on the screen.

    There is a registry work-around for keeping the GUI active for minimizing the window, but I know of no way to keep it alive after disconnect.

    Ideally, I would have this run on the server Windows console session which would not care about being disconnected but in a hosted environment (I tried Amazon and Go Daddy) there is no way to access the console session.

    Does anyone know how I can get around this? Basically any solution that allows me to run my application on a VPS. I need the reliability of a host but the flexibility to run it as if I was sitting right in front.

  • user2029890
    user2029890 over 10 years
    Getting back to this after a few months - this solution DOES work. I log in with RDP 1 on a server and from there connect to RDP 2. When I disconnect from RDP 1, RDP 2 remains active. thanks.
  • whywhywhy
    whywhywhy over 3 years
    You saved my day Mr. Alex.
  • Benny K
    Benny K over 3 years
    At least for Windows 10 it's no longer the case: if you disconnect from myslave.com, then myserver.com also loses GUI context.
  • user2983041
    user2983041 almost 3 years
    I get error in command run: "%%s was unexpected at this time"
  • LPChip
    LPChip over 2 years
    @user2983041 %%s is for when you run this from inside a .cmd file. if you run it in a command prompt, it should be %s instead.