Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to ssh into Windows (through a cygwin sshd) and start a program on a logged in Windows user's desktop?

Is it possible to ssh into Windows (through a cygwin sshd) and start a program on a logged in Windows user's desktop?

Put another way, say a user ABC is logged in on windows and a remote user logs in with ABC's login/password over ssh, can remote ABC pop up an app on the local ABC user's desktop?

I am asking this on Stackoverflow and not Serverfault because the motivation for doing this is programmatic in nature. The remote call will be coming from a Linux box so while it may be possible(?) to do this using WMI or some other approach, ssh seemed like the simplest.

Happy to hear simpler/better alternatives though.

Thanks!

like image 571
Atlas1j Avatar asked Nov 06 '22 18:11

Atlas1j


2 Answers

If your cygwin sshd is running under a privileged account, it can get a handle to the current desktop and put windows on it. See the desktop parameter of STARTUPINFO for CreateProcess.

like image 97
bmargulies Avatar answered Nov 15 '22 01:11

bmargulies


My own solution. Tested on windows XP (but I think it should run in any windows environment with a little effort).

You need to use the psexec and quser command.

First, put psexec and quser in a directory included in the cygwin's PATH environment variable. Just copy these files into the bin directory under cygwin.

You can find the quser.exe in your %system32%\dllcache dir. But for any reason I can't access to it (or access to the mentioned directory) through cygwin commands (i.e. ls, cp, etc), so I made a copy using the microsoft's copy command to the cygwin\bin folder.

Notes: I think it's helpful to have the suite psutils all in the bin folder of cygwin. The first time you run either of these utilities will have to accept a license agreement from Microsoft warning, so run psexec from Windows explorer the first time.

Then create these alias in your .bash_profile file:

alias winrun='psexec \\\\YOU_USERNAME_HERE -d -i `quser | grep YOU_USERNAME_HERE | grep console | awk "{print \\\$3}"`'
alias explorethis='winrun explorer $(cygpath -w `pwd`)'

Remember that you will need to translate the current directory using cygpath if you need to pass it as argument of a command ("explorethis" is an example of that).

like image 43
Federico Valido Avatar answered Nov 15 '22 02:11

Federico Valido