Windows server 2012 Log Off a remote desktop session without locking the screen - windows

As in title. Is there any way to achieve this?
I have problem, because when you close remote desktop, gui and whole interface is being locked and any gui based applications or my autoit scripts won't work (they are crashing constantly).
I tried using 'tscon.exe' but this works only on windows server 2008.

I have the same issue, and I resolved it doing the following:
Connect to RD to your server with user "A"
From the remote computer, connect to RD to localhost to user "B" (create it if necessary)
From the new session, run anything you need.
Disconnect the FIRST session, with user "A".
In this way, the session running with user "B" will not be locked, and it will continue running your GUI controls.

Log off means the current session (created by logging in during RDP) is terminated. What you want is to keep the Logon Session live but disconnect the RDP.
Why not use AutoLogon to boot into console and run the scripts? However if the screen locks or someone RDPs and disconnects, the problem you are facing will reoccur.

What I have is to keep GUI and whole windows interface alive when i close remote desktop. Session is alive but gui and whole workstation is getting locked everytime I close rd.

Related

How to open GUI application on Windows via SSH if no active user sessions?

I am working on a project where I need to run a few tests through SSH using an interactive GUI application on multiple Windows VMs. I have seen various other solutions here for launching the GUI application such as with psexec or running schtasks and a .bat file. I have tried all of that. Unfortunately, the only time the GUI opens is when there is an active user session. For example, if I do something like psexec -i 22 path\to\bat\file it will launch the GUI with my active RDP session. This will still work while I am disconnected, as the user session is still active. However, if I log out of the user session entirely and try the same (either with psexec or directly running a bat with schtask), it won't work. It will simply run the GUI application as a background process, as when I login again with RDP, the GUI isn’t present and it only shows as a background process in the task manager.
Is there a way to trigger an RDP or some GUI style user session to become active in a headless manner? If not, then is there a different way to execute my application, where the interactive GUI is available with SSH or other means of headless connection when there is no active user signed in?
The Windows VMs have OpenSSH server running for connections.
This question actually solved the other half of the puzzle for me, namely how to get SSH connections to use the interactive session. Here's how to keep an active interactive session open at all times. Note that depending on your use case you might explicitly need a multi-session windows installation, which is a different VM image in Azure for example.
Have the user you want these commands to run in log on automatically when windows boots. https://learn.microsoft.com/en-us/troubleshoot/windows-server/user-profiles-and-logon/turn-on-automatic-logon
Create a .bat file with the following contents somewhere (for me it's just on C:) tscon 1 /dest:console
In task scheduler, create a task that runs this bat file whenever a remote user disconnects.
Point 2-3 are not necessary if you never RDP into the autologon user. Whenever you RDP to this user, the console session moves from the autologon session to your RDP session, and this script just reattaches the console session back when you disconnect. This way, that user always has the console attached and thus has GUI available.

Freeze keyboard and mouse on Windows

I want to create a program for a computer lab. The computers in lab are running Windows 7 and are connected via LAN. The program should freeze keyboard and mouse when PC gets disconnected from LAN and also show a fullscreen message.
Currently I have created the first version of this program that works almost fine. It runs with startup. But the problem is that the users can kill it from Task Manager. I've tried running it as a windows service and it runs but cannot interact with desktop, so it cannot freeze the keyboard and mouse.
Any suggestions is appreciated. Thanks in advance.
So I finally solved it.
The reason my program could not interact with desktop is that it runs in Session 0.
This is because the Windows services run in session 0 and cannot directly interact with desktop. Here by interaction I mean receiving keyboard, mouse events and creating or accessing windows in user's desktop.
So I created a service that runs with SYSTEM account. It will create the "freezer process" in user's session. Also this process will run with SYSTEM account, so the normal user will not have privileges to kill.

Keep windows GUI while switching windows user or closing remote connection

I need to run a GUI script (AutoHotKey, which makes mouse clicks and press keys) on:
A different windows user (i.e. I run the script, then switch user
while keeping the session active)
A remote Amazon windows server (using remote desktop) where I also
run the script then close the Remote Desktop while keeping the
instance running
Unfortunately, in both cases, the script doesn't run as it seems that Windows enters a "GUI-less" mode where all GUI components are not active anymore.
Is there any solution to this?
Any hint would be greatly appreciated as I've now lost days trying to solve this!
Many thanks, Thomas
I do not believe this is possible due to the way Remote Desktop is implemented. When you close the RD connection, the GUI is no longer drawn. Therefore, AutoHotkey is unable to perform mouse clicks and key presses.
A possible workaround would be to make some registry tweaks (if possible on your server) which allow GUI interaction while minimized.
Locate HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client
Create RemoteDesktop SuppressWhenMinimized as DWORD with a value of 2
Registry Tweak Source

Terminal session when minimized\disconnected returns a blank screen upon capturing desktop snapshot

I am using the below JAVA code to capture the desktop of a remote machine
Robot robot = new Robot();
BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ByteArrayOutputStream imageBytes = new ByteArrayOutputStream();
ImageIO.write(screenShot, "PNG", imageBytes);
return imageBytes.toByteArray();
However the captured image is blank, when the terminal session to the remote machine is either minimized or disconnected. I appreciate your help in resolving the issue, at the very least the minimized scenario.
Configuration:
I have the same issues with a physical machine running windows 7 and a virtual machine running windows server 2008 R2.
More insights from MSDN:
Why you get black screen when you disconnect from RDP ?
 
http://msdn.microsoft.com/en-us/library/aa383015%28VS.85%29.aspx
Here is my attempt to make things work, but none of the following did the trick:
 
How to get data when RDP window minimized ?
 
You can force the RDP display driver to send data when minized, try these steps and let me know how it goes:
 
1) Add the following key
HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client\ Created a new DWORD value and named it RemoteDesktop_SuppressWhenMinimized. Specified 2 as the value data.
Note: Also tried adding the registry key to HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Terminal Server Client\
 
2) Disable bitmap caching (http://technet.microsoft.com/en-us/library/cc737325(WS.10).aspx)
In the Remote Desktop Connection window, click Options.
On the Experience tab, verify that the Bitmap caching check box is selected. Or, to disable bitmap caching, clear theBitmap caching check box
If you minimize the Remote Desktop window, Windows switches the remote session to the GUI-less mode and does not display windows and controls. As a result, TestComplete (or TestExecute) will be unable to interact with the tested application’s GUI, as it does not exist and your automated GUI test will fail.
To work around the issue, you can change the Remote Desktop’s registry settings on your local computer (where you launch the Remote Desktop):
On your local computer, close all open Remote Desktop sessions.
Launch the Registry editor (regedit.exe).
Navigate to one of the following Registry keys, depending on whether you wish to modify the Remote Desktop settings only for the current user or for all users on the computer:
HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client
HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client
Create a DWORD value named RemoteDesktop_SuppressWhenMinimized and set it to 2.
Or you can do it programmatically by following steps:
Transparent the window
Restore the Window
Capture
Minimize it again
Remove transparency
We had similar problem in our project last year...we could find any stable and permanent solution....however here is how a work around worked for us...
We had to run on 5 remote desktops (which will take screens capture as well during failure) ..however as you have figured already if we disconnect session or minimise the RDC Window blank screenshot is captured. Therefore we had added one more VM to connect those other five test boxes. The task for that VM is to keep session active and resized to other 5 boxes...this worked for us.
If you connect a remote desktop to the test machine, make sure to reboot the machine when you are done, otherwise the desktop will remain locked and screen captures will not work.
I don't believe there is any other way around the issue.
I just configured the clients to auto logon, disabled the screen saver and installed a VNC server on each client.
Basically, make sure the screen is always on, and don't RDP into them.
This worked on both physical PCs and on virtual machines hosted on a Hyper-V server.
I even wrote a small .NET desktop client that ran multiple VNC clients inside a single window, so we could see what was happening on all the clients. We had an old PC running this with it's monitor on top of a cupboard to (a) let the developers see if any client had hung, had hundreds of browser windows open, etc. and (b) to look impressive for any non-developers walking past.
A simpler alternative to the above answers to to transmute the terminal session (RDP) into the console session. The session will then display to the physical screen (Switching the user of anyone currently logged into the physical machine). The following command does this:
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (tscon.exe %%s /dest:console)

Prevent lock of windows detecting user idle time

I work in a Windows Terminal Server enviroment where if you left the computer for a while, windows lock the session and terminal is power off.
What i need is the code needed to send a message to Windows for it to believe the user is in front of the PC (mouse or keyboard activity).
Thanks in advance
Can you run mstsc with the /console parameter? This will get you in console mode and wont time out. The screen will lock with the normal timeout, but you wont get disconnected. Be careful though, as anyone else trying to get into the console will then need to log you out in order to get on.
You can control session disconnect (connection is closed but session remains open and can be reconnected) and reset (connection and session are closed) timeouts via local or group policy.
Make sure screen saver on remote server and local PC is set to some ridiculous amount like 960 minutes (8 hours). Open a command prompt on the remote server. Tape the enter key down on your local keyboard. The system will interpret this as user activity. It won't affect performance or mess anything up. Any your boss will think you're working while you're off playing XBOX360, or watching a movie, or smooching with a co-worker in the emergency stairwell.

Resources