SSH issues when executing: Can't find native windows

Mar 14, 2014 at 6:31 PM
For reasons that I'm not at liberty to fully explain (but it has to be this way) I need to ssh from my windows box to a linux box back into my windows box. I have a python script that is run from the linux box which then executes the powershell script via ssh.

This seems to present a problem to the UIA extension. My powershell script runs flawlessly on the windows box before ssh, but when I execute the python script or try to run the PS script from via windows>linux>windows ssh, it doesn't recognize any of the windows objects.


Get-UIAWindow : Object reference not set to instance of an object

Get-UIAChildWindow : Cannot validate argument on parameter 'InputObject'. The argument is null or empty....

These windows exist as, like I said, the script is fine when run locally, but I'm assuming that by doing ssh from the linux box into the windows box, the UIAutomation can't "see" the windows anymore.

Is this the case?
Has anyone else run into this?
Is there a work around?
Am I missing someting? etc. etc.?

Any insight or help would be much appreciated.

Thanks for the help, mates.
Mar 14, 2014 at 8:22 PM
Hi CronusIX,
is your Windows box with Vista+ system and your ssh server on Windows is a Windows service?
In that case you are trying to work from the session 0 that doesn't support GUI and user session at all.

If so, you have two options:
1) RemoteApp
  • you need to create a RemoveApp in the Registry (for example, c:\folder\file.cmd)
  • create the file c:\folder\file.cmd
  • add something like
    powershell.exe -sta -executionpolicy bypass -noninteractive -command "& { your_powershell_script.ps1 parameters; }"
  • put PowerShell script(s) in place
    and run an RDP client from your Linux box
I described all that one needs to implement this scenario here

This option is native and works good. To check that there is no sessions in parallel or that the session is finished, there are cmdlets by Shay Levi that works without a user session.

2) tools like PsExec (PaExec, RemCom)
These tools are not native and their ability to work in a user session from the session 0 is limited.

If your ssh server on windows is not a Windows service, or your operating system is lower than Vista, I hope there should be one more solution.

Feel free to ask for more details on way 1 (hardly can I help in the way 2), or provide info about your Windows operation system, your ssh server and a way you run the script (command line).
Mar 14, 2014 at 11:02 PM
Forgot to mention, if your Windows ssh server is running as a service and could be running as an executable, this may also be the way.
Mar 17, 2014 at 5:39 PM
Edited Mar 17, 2014 at 5:39 PM
Makes sense and I did more research on the session 0 thing. Seems to be an issue for a lot of people with no real good answer.

Do you know if there is a way to manipulate the session (change to session 1) from ssh or from powershell because I can't do the RDP client.
Mar 17, 2014 at 6:33 PM
There's no honest way for your scripts to go beyond the session 0 (if the system is Vista, 2008 or higher).
There's API (people complain that the memory provided is limited for real-life applications) and tools PSExec, RemCom, PaExec.
If your application is rich (i.e., many controls), there is little chance to work well.
If your app is tiny or you need no GUI (for example, I use object model of the application under test just because the model signals to a windows service with WCF interface, and I can't access such WCF interface from session 0 unless programmers extend ACL of named pipes, they refused, so that I use RemCom to access WCF as from user session :)) - this way could be okay for you.

Put a tool to a folder, add cmd files like below (scripts run the first cmd, the cmd runs via RemCom, which connects to a target system, the second cmd (StartTask.cmd)):
C:\TESTHOME\libs\RemCom\RemCom.exe \\%1 /user:%2 /pwd:%3 C:\TestHome\libs\RemCom\StartTask.cmd %4 %5
rem %1 host
rem %2 domain\user
rem %3 password
rem %4 %5 parameters for StartTask.cmd
SET powershellCommand="& { $global:TestHome = 'C:\TestHome'; New-Item -Path 'C:\TestHome\Logs' -ItemType directory -Force -Confirm:$false; New-Item -Path 'C:\TestHome\Reports' -ItemType directory -Force -Confirm:$false; ipmo C:\TestHome\PSModules\LogManager; $global:Logger = Get-Logger C:\TestHome\Logs\StartTask.log debug 5; ipmo C:\TestHome\PSModules\GuiConsoleCommon; GuiConsoleCommon\Start-ManagedObjectDataCollection %1 %2 }" > C:\TestHome\output1.txt >> C:\TestHome\output2.txt
echo %powershellCommand%
powershell.exe -sta -noninteractive -executionpolicy bypass -command %powershellCommand%
These tools use API with some hacks to partially access the user session. My code works without the user session existing before scripts start RemCom. Code to hit the GUI may require that a user session under the same user be available. You need to experiment.