I've got Mac OSX running and want to programmatically manipulate a active RDP session to for instance, perform actions within a launched program within the session (dynamics specifically, yet woudn't hurt to know a universal way).
I don't know if this is possible. Currently using a RDP file to launch the RDP session with credentials and have the process ID of my active session, retrieved via NSWorkspace. With that I can do the basic stuff like closing my session again, yet i want to manipulate the session.
My RDP client currently is Microsoft Remote Desktop.
Would wish to reach my goal in either bash or python.
Here are few ideas:
Use Quartz graphics library in Python to manipulate with RDP client window. Here is a good start: How to list all windows from all workspaces in Python on Mac?
Use libfreerdp via ctypes.
Run RDP session under Wine and use tools such as AutoHotKey, AutoIT or xdottool. See: How to programmatically control X11 forwarded apps?
Use WinRM (pywinrm) instead of RDP to run remote commands/scripts. Check this example. This can allow to run auto tools mentioned above (e.g. AHK script controlling the apps).
Use Python GUI automation library for simulating user interaction in apps.
See also: GUI scipting for Linux.
Write an RDP client that dumps the pixels of the screen. E.g. WebRTC or using libFreeRDP.
If RDP client runs via X11 protocol (Quartz), you can try to tap into X11 requests as per this post.
Use FreeRDP and its API. Its client is compatible with Linux, macOS and Windows.
Related
I want to automate a very old software (drafix) that can only be run in Windows XP, on a remote desktop.
Would it be possible to write a pywinauto script that would directly interact with the software controls, without the need to send mouse/keyboard clicks on the GUI, and then minimize the Remote Desktop screen or even lock the PC?
I need to open the program, loop through a list of file names, open each one of them and save as a different format.
I did it with some basic GUI automation - clicking on buttons if necessary, sending keyboard shortcuts and entering the file names form a list. But it isn't very reliable, and I would like to minimize the Remote Desktop window and use my PC instead of having it in the foreground.
From what I have read here, it should be possible with some workarounds, and I would need to install an older version of Python (any idea which one?) on the remote desktop to write and run the script there.
What you can do is just copying your script to remote machine and run it there. Regarding minimized or closed RDP there are few workarounds and tricks described in the Remote Execution Guide which summarizes few StackOverflow answers.
There is other way that you can control gui application on remote Desktop with pywinauto. You can use rpyc or Remote Python Call. that is a python library for rpc(remote procedure call)
https://rpyc.readthedocs.io/en/latest/
your remote computer is as server and your host is as client in rpyc.
first you you need to run rpyc_classic.py in remote computer after connect to it and use pywinauto library. for example i use rpyc for start microsip on remote computer with pywinauto.
ip of remote computer is 192.168.222.222.
import rpyc
ip = "192.168.222.222"
conn = rpyc.classic.connect(ip)
conn.execute("from pywinauto import Application")
conn.execute(r"Application().start(r'C:\Program Files (x86)\MicroSIP\microsip.exe')")
I tried to do this with WMI, but interactive processes cannot be started with it (as stated in Microsoft documentation). I see processes in task manager, but windows do not show.
I tried with Paramiko, same thing. Process visible in task manager, but no window appears (notepad for example).
I tried with PsExec, but the only case a window appears on the remote machine, is when you specify -i and it does not show normally, only through a message box saying something like "a message arrived do you want to see it".
Do you know a way to start a program remotely, and have its interface behave like it would if you manually started it?
Thanks.
Normally the (SSH) servers run as a Windows service.
Window services run in a separate Windows session (google for "Session 0 isolation"). They cannot access interactive (user) Windows sessions.
Also note that there can be multiple user sessions (multiple logged in users) in Windows. How would the SSH server know, what user session to display the GUI on (even if it could)?
The message you are getting is thanks to the "Interactive Services Detection" service that detects that a service is trying to show a GUI on an invisible Session 0 and allows you to replicate the GUI on the user session.
You can run the SSH server in an interactive Windows session, instead as a service. It has its limitations though.
In general, all this (running GUI application on Windows remotely through SSH) does not look like a good idea to me.
Also this question is more about a specific SSH server, rather that about an SSH client you are using. So you you include details about your SSH server, you can get better answers.
ok i found a way. With subprocess schtasks( the windows task scheduler). For whatever reason, when i launch a remote process with it , it starts as if i had clicked myself on the exe. For it to start with no delay, creating the task to an old date like 2012 with schtasks /Create /F and running the then named task with schtasks /Run will do the trick
I am using a virtual private server (VPS) running Windows Server 2012 R2 Base on Amazon web services (AWS)
I am using Python imaging library and win32api to simulate mouse clicks and take screenshots.
I would like to be able to do this even when the remote desktop is not connected.
As soon as I disconnect there is no monitor available and my python program stops because it cannot click anywhere (there is no screen to click on)
Is there a way to setup a "fake" monitor or display for my VPS so it can continue to click away happily?
This is possible through the tscon command - where you can disconnect from the RDP session but the terminal is still available. I am not sure whether this will work for your python program.
The command is tscon, an example of the use is:
C:\Windows\System32\tscon.exe rdp-tcp#1 /dest:console
This depends on knowing the RDP session identifier (rdp-tcp#1 in this case). If you use the qwinsta command in a command shell. As seen below this shows the currently active session name for use in the tscon command. One issue is that each time you RDP in the session increments so you have to use the new session name each time.
C:\Users\Administrator>qwinsta
SESSIONNAME USERNAME ID STATE TYPE DEVICE
services 0 Disc
>rdp-tcp#1 Administrator 2 Active
console 3 Conn
rdp-tcp 65536 Listen
I am working with the VirtualBox python API and am trying to open a VM window in fullscreen mode. I have been unable to find an API command to do so, so I am trying to use the win32api to send a keyboard command of F8+f (F8 is my host key since there is no SendKeys code for Right Control) to the application, but am not succeeding in this endeavor. My code follows, any ideas?
import time,win32api,win32con,win32com
shell = win32com.client.Dispatch("WScript.Shell")
#The title of the application was copied from the Task Manager
shell.AppActivate("fed (Snapple) [Running] - Oracle VM VirtualBox")
win32api.Sleep(100)
shell.SendKeys("({F8}f)")
hey check this out ..may be it helps you..
This is pyVBOX, a shim layer above the VirtualBox Python API.
Why? Becuase the VirtualBox Python API is somewhat complex and I got
tried of trying to remember all the details of its use. Plus it
changes from release to release and this gives me an abstraction layer
to hide those changes. The software also includes a script,
utils/pyVbox.py, that provides the ability to manipulate VMs (like
VBoxMange).
This code is written to the 4.1 version of VirtualBox (4.1.12
specifically). I have not tried it against any other version.
This software is independently created from VirtualBox and Oracle. No
endorsement by Oracle or the VirtualBox authors is implied.
pyVbox
This is my scenario: I developed a Python desktop application which I use to probe the status of services/DBs on the very same machine it is running on.
My need is to monitor, using my application, two "brother" Window Server 2003 hosts (Python version is 2.5 for both). One of the hosts lies in my own LAN, the other one lies in another LAN which is reachable via VPN.
The application is composed by:
A Graphical User Interface (gui.py), which provides widgets to collect user inputs and launches the...
...business-logic script (console.py), which in turn invokes slave Python scripts that check the system's services and DB usage/accounts status/ecc. The textual output of those checks is then returned back to the GUI.
I used to execute the application directly on each the two machines, but it would be great to turn it into a client/server application, so that:
users will just be supposed to run the gui.py locally
the gui.py will be supposed to communicate parameters to some server remakes of console.py which will be running on both of the Windows hosts
the servers will then execute system checks and report back the results to the client GUIs which will display them.
I thought about two possible solutions:
Create a Windows service on each of the Windows hosts, basically executing console.py's code and waiting for incoming requests from the clients
Open SSH connections from any LAN host to the eliged Windows host and directly run console.py on it.
I am working on a corporate environment, which has some network and host constraints: many network protocols (like SSH) are filtered by our corporate firewall. Furthermore, I don't have Administration privileges onto the Windows hosts, so I can't install system services on them...this is frustrating!
I just wanted to ask if there is any other way to make gui.py and console.py communicate over the network and which I did not take into account. Does anyone have any suggestion? Please note that - if possible - I'm not going to ask ICT department to give me Administration privileges on the Windows hosts!
Thanks in advance!
Answer to myself: I found one possible solution..
I'm lucky because the console.py script is actually invoking many slave python scripts, each of them performing one single system check via standard third-party command-line tools which can be fired to check features on remote hosts.
Then, what I did was to modify the gui.py and console.py so that users can parametrically specify on which Windows host the checks must be carried out.
In this way, I can obtain a ditributed application...but I've been lucky, what if one or more of the third-party CL tools did not support remote host features checking?