SSH launch gui application on Windows

Hi there,

I’m trying for a while now to do the following:
Launch a windows application in GUI mode, so the interface will popup and the application is not just starting in the background as a service.

At the moment I’m working with SSH which is setup correctly as I want it.
When I test it with for example “calc” the calculator launches on the target machine.
explorer works as well, and will launch a new windows explorer instance.

But if I try to open notepad(.exe) for example, it just opens the application in the background.


As you can see the notepad only appears under the details tab and not under the processes.
Also there will never be a notepad window visible.

I’m using this for a few other applications as well.
And they require to be opened as a gui cause they won’t work otherwise.

Thanks for the help!
Pieter

See user interface - Starting GUI programs via OpenSSH on Windows? - Stack Overflow
This is really a question about Windows and not Home Assistant.

Ok, thanks for the reply.
I was just trying to further advance the integration of windows applications.

Is there a good way to test this interactively?
At the moment I managed to do what I want with the following command:
The following code is what I’m using on a windows machine

psexec \\192.168.1.*** -u username -p password -d -i 1 server

the “-i 1” is for user 1 which runs the command in interactive mode, with a visible interface.
the “-d” makes sure the code runs without waiting for a return code.

Is there a way to make this work in HA running on linux?
I found that winexe under linux should be able to do the same as psexec.

Also, is there a way to debug this code interactively, like in HA terminal?
Thanks a lot
Pieter

I would try connecting to the Windows machine with ssh and then using psexec on localhost, as suggested in the Stack Overflow answer I linked in my previous post.
So, to adapt your example:

ssh windows_machine "psexec -d -i 1 server"

I have no idea how secure the psexec protocol is, but this is Windows, so I assume it’s better to not expose it to the network.

Hi Ondras,

Thanks for your reply. Indeed the earlier referenced link did show this kind of code to run a remote application in interactive mode on a windows machine.

After searching and a lot of train and error, this seems to work:

ssh [email protected].*** "psexec \\\\192.168.1.*** -u user -p pw -d -i 1 aplication.exe"

Some questions about the use of ssh here:

  • at the moment I’m getting the request for the password each time. Is it possible to embed the password in the code here so with one line everything can bet set.
  • the command that’s been passed through here psexec… lookst to me to be overkill, cause we’re already in the remote machine. So what we have to do here is inside of the remote machine, to launch a psexec command to remotely launch the application, where the remote machine is this machine itself…
  • This whole loop is needed because I can’t find a way to run let’s say notepad.exe interactively (so that you see the notepad windows popping up) when just running notepad after connecting through ssh. So any tips are welcome here.
  • Is there a way to just launch a command through ssh without waiting for a response. Like the -d flag in the psexec command.

Thanks a lot
Pieter

Including your password in plain text in the command would be extremely insecure.
Use SSH public key authentication instead.

What happens if you don’t specify host, username and password for psexec? I thought it was supposed to connect to localhost in that case.

ssh [email protected].*** "psexec -d -i 1 aplication.exe"

You should be able to tell your shell to not wait for ssh to finish by appending & to the end of your command. e.g. ssh host sleep 10 &.
However, I’m not sure if you need to do this. I’d expect psexec -d to terminate almost immediately.

Indeed, using the password in plain text isn’t the best way to go here.
But getting access from HA into the Windows machine through ssh using a set of keys is pretty hard to get working.

I’ve generated the key on my windows machine on OpenSSH with the default settings.
using ssh -vvv user@ip I’ve the logs, I can share them personally if anyone would like to ckeck them.
What’s mainly concerning to me is the following

debug1: Will attempt key: /root/.ssh/id_rsa RSA SHA256:*******************
debug1: Will attempt key: /root/.ssh/id_dsa
debug1: Will attempt key: /root/.ssh/id_ecdsa
debug1: Will attempt key: /root/.ssh/id_ecdsa_sk
debug1: Will attempt key: /root/.ssh/id_ed25519
debug1: Will attempt key: /root/.ssh/id_ed25519_sk
debug1: Will attempt key: /root/.ssh/id_xmss
...
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa_sk
debug3: no such identity: /root/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519
debug3: no such identity: /root/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519_sk
debug3: no such identity: /root/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /root/.ssh/id_xmss
debug3: no such identity: /root/.ssh/id_xmss: No such file or directory

The root here is that referring to the windows user folder?
C:\Users\user***
That’s where I have my public and private key stored.

When using:

"psexec -d -i 1 aplication.exe"

It seems to be executed in the background and nothing visibly happens, which isn’t working for us as we need the application needs to popup for it to work.

No, I think you are logged in as the root user on the ssh client machine, and you don’t have any ssh keys in $HOME/.ssh/.
Have you generated a set of keys on the client? You’ll also need to put the client’s public key to the server’s authorized_keys file.

So this is my configuration at the moment.

Connecting from the windows machine (using mobaXterm as client) to the HA running on a proxmox VM works without a problem. The key does it’s work and I can login without entering a passphrase/word.
The other way around from HA > WindowsMachine isn’t working. Yet has the same workflow with shared key added in the autorized_keys.

At the moment I’m getting another error there.
When connecting from HA > WM I get:

.ssh $ ssh -v [email protected].***.***
OpenSSH_8.4p1, OpenSSL 1.1.1k  25 Mar 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to 192.168.***.*** [192.168.***.***] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type 0
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa_sk type -1
debug1: identity file /root/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: identity file /root/.ssh/id_ed25519_sk type -1
debug1: identity file /root/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /root/.ssh/id_xmss type -1
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.4
kex_exchange_identification: read: Connection reset by peer
Connection reset by 192.168.***.*** port 22

Thanks!

It seems like this can be caused by a lot of different issues.
First, I would try restarting the sshd service on the Windows host.

Was it working previously with password authentication instead of keys? Try ssh -vvv -o PreferredAuthentications=password -o PubkeyAuthentication=no [email protected].***.***.
-vvv should show more debug messages than just -v.