8

I'm trying to execute a labview VI, launching that from a .bat file, called via ssh, from another Windows machine. So I do

 ssh myuser@IP
 cd  Desktop
 launchVis.bat

I connect with user and password. myuser have all the rights to launch the batch file. Meanwhile I check the execution via RDP connection on the same machine.

If I run the bat file from a cmd line on the remote machine, the VI starts normally If I run the bat file from the ssh connection, i can see the output of echoes in the bat file but LabVIEW will be launched in a different session from RDP-TCP#1. The result is that I can see a "LabVIEW" process started in a Session named Services, but I cannot see the VI executing and in general, I don't know IF is executing or not.

Googling about the problem, It seems that I cannot avoid to start processes in "Services" Session and, for this reason, I cannot launch any GUI Program via SSH. Suggested solutions are using PsExec or, maybe a third part of ssh Server (with a third part ssh Server I reached my goal over Windows 7)

ALEX
  • 151
  • 1
  • 1
  • 6
  • It seems that if you want to launch a GUI interface, you should launch sshd server as user and not as a Service. Unfortunately, if you try to launch it as a User, even with administrator privileges, it fails. – ALEX Jan 23 '20 at 17:35

2 Answers2

8

Running SSHd as a service makes launching desktop applications difficult, because a service has no access to the user desktop (Windows Station, WinSta0) link

Option 1: Start SSHd as a user

  • This fails with the latest OpenSSH implementation with fork of unprivileged child failed, as running SSHd as a user is no more possible since OpenSSH 7.5 released in 2017 link
  • Use an old implementation or a fork of OpenSSH, e.g. dropbear, FreeSSH or similar

Option 2: Use a launcher that has access to the Windows Station

On Windows, there are 2 options left to launch desktop applications over SSH: link to Github OpenSSH issue

  • schtasks
  • psexec on localhost

Usage:

ssh user@host "psexec -i 1 mydesktoplauncher.bat"

See psexec documentation for optional arguments like -i 1

Bumsik Kim
  • 5,853
  • 3
  • 23
  • 39
domih
  • 1,440
  • 17
  • 19
  • 1
    Hi Domih - i tried the above psexec command but seems it just gets stuck - i am trying something very basic - C:\PSEXEC>ssh Administrator@xx.xxx.xxx.xx "psexec c:\windows\regedit.exe" PsExec v2.34 - Execute processes remotely Copyright (C) 2001-2021 Mark Russinovich Sysinternals - www.sysinternals.com Should i expect regedit to open with this? Authentication is key based and works correctly without the psexec command Server has OpenSSH, any pointers? – Monojeet Nayak May 26 '21 at 11:07
  • You try to call a program which requires elevated privileges. I would assume, UAC asks for your administrator password if you call it directly using command line. My experience is within the user context and how to bring an application to the user desktop. You could try to invoke runas, but this is basically where the real ugly things begin.. – domih May 31 '21 at 06:45
6

The "solution", using a third party ssh server is this:

  1. Uninstall the Optional Feature "OpenSSH Server" of Windows10
  2. Download and install the third party ssh server. I used freeSSHd
  3. DO NOT install this software AS AS SERVICE.
  4. Set users allowed in the Settings of the software.
  5. Put a link to the exe of this software in the shell::startup folder, so it will be run at startup.

In that way, the ssh server will be launched as user and CAN execute GUI programs.

Unfortunately, I didn't manage to achieve the same goal with the Windows official OpenSSH server, because it fail to be launched as User, but seems working only as a Service

alastairtree
  • 3,960
  • 32
  • 49
ALEX
  • 151
  • 1
  • 1
  • 6