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

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.

Related

Why does this command not work on Windows via SSH?

I'd like to send websites to be opened on my Windows PC from my MacBook via some automations involving SSH.
The following command works fine when I'm running it on my PC, but it only shows up in the task manager when I run it via SSH.
"C:\Program Files\Mozilla Firefox\firefox.exe" -private-window reddit.com
Tried to use it with the runas command as well.
Any idea?
Thanks.
The SSH session works like a normal user session, except it's not given access to the UI (meanings, SSH has no start button to click on, no firefox window and so)
While firefox DOES PROVIDE a way to run the browser for headless (no UI) sessions, you're still expecting your SSH user-session to do something as your non-ssh user session. This is why you see the process running, but you don't see the window.
Please have a look at different thread on the SE:
https://unix.stackexchange.com/questions/10121/open-a-window-on-a-remote-x-display-why-cannot-open-display
Which explains how to achieve what you want in a different way

Open a window on windows server in a user desktop from the SYSTEM level cmd

I came across an issue that I'm not entirely sure it is even possible.
I want to start a process (chrome browser for ex.) on a user desktop using a system level command prompt or powershell.
I tried many imitations such as runAs and -Credentials but they only open the process in the background "as" the user, not on the user's desktop. I want to actually RDP to the user's profile and see the browser open.
I'm aware there are risks of using system. This question is mostly on how to start a process on a specific user desktop rather than just appearing on task manager.
Edit to clarify the issue:
I'm using windows server which has several of users, all of them are users that i have their name and password.
On that server, i have a process running under SYSTEM which i need it to open a process with a UI (a browser for ex.) in one of the other users's desktop.
The user's session is open and runnign and i can RDP/VNC/SSH/whatever to it and open whatever i want but that is not what i need. I want to RDP to that user after the browser was opened and see that it is already opened.

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

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.

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

Selenium grid 2 over cygwin

Ok, this is a tricky one. I'm trying to set up a Selenium Grid 2 with some Windows 7 VMs to run Webdriver tests. To automatize the whole process I use some ant script that connects to the VMs through ssh to start/stop/reconfigure the nodes.
Everything works great, the nodes can register with the hub host and execute the test. Only problem is that I don't see any browser window during the test run. I can see the process and I see the test log being executed, but there is no graphical interface.
On the other hand, if I start the node manually through Windows, everything is normal.
I suppose the problem is that processes executed under cygwin cannot start Windows displays, but in that case, shouldn't throw an error? The other option I'm thinking is that Webdriver is using HTMLunit as a fallback, but then... why do I see the firefox process as long as the test lasts and consuming CPU and memory?
Through ssh, you only exchange with Windows stdin, stdout and stderr streams. The ssh connection is tunneling those streams and nothing else. You don't see Windows Desktop interface, but the Desktop object exists on the Windows machine, the programs (here the browsers) are connected to it, and all GUI interactions are live in there.
If the GUI doesn't require any user interaction, everything is fine that way. The dialog boxes are created, the program runs, once it finishes, the dialog boxes are destroyed by the application and the application closes. Nothing is blocking in terms of GUI our application.
If you program requires an user action in the created yet invisible dialog boxes, your program will be there waiting for your interaction to move forward. You will see the process in the task manager, doing nothing but waiting. As you don't have access to the Windows Desktop where the dialog boxes are created and virtually 'displayed', the program seems to hang.
A typical case 2 is if you remote run a program waiting for a user to do something, say notepad. You can launch notepad, it will be spawned and then it will wait for you to type some text or close it.
With your Selenium tests, you are in case 1: all the browsers' interactions needed to make the GUI working are actually done by Selenium server that does the navigation clicks and the program exit for you. Their GUI actually are living by browsing through your test web servers, you just don't see it.
Some further readings from Microsoft website on Desktops and Desktop Creation.
If you want to see the tests and have valid screenshots, you need to have a user logged in and those tests need to run as that user. Everything must run through that single desktop session, so you cannot use RDP to remotely connect to the machine. Your best bet is to use VNC, since that will connect to an already established session.

Resources