Skip to content

Commit

Permalink
Extend Remote Execution Guide with PsExec, Ansible and Windows Schedu…
Browse files Browse the repository at this point in the history
…ler ways.
  • Loading branch information
vasily-v-ryabov committed Nov 4, 2018
1 parent d900e0c commit e69bb41
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions docs/remote_execution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ There are few methods for silent text input in ``backend="win32"``:
* ``send_keystrokes``


Start remote script from local machine
--------------------------------------
Start remote script using agent based CI
----------------------------------------

When your script is ready and you can run it on a remote machine manually,
it's time to automate the last step: trigger running the script from local
Expand All @@ -89,7 +89,54 @@ three ways to connect agent:
* Run agent through SSH: GUI tests won't work.
* Run agent as a normal application. This is the only working case!

TODO: how to run using psexec and Ansible.

Start remote script directly
----------------------------

This chapter is inspired by `issue #401`_ (special thanks to `yangliang003`_).

.. _`issue #401`: https://github.com/pywinauto/pywinauto/issues/401
.. _`yangliang003`: https://github.com/yangliang003

First option is PsExec. Thanks to `this post on StackExchange`_.

1. Download `PsTools`_.
2. Get process ID of RDP session using ``tasklist`` command. PowerShell script:
::

$session = tasklist /fo CSV | findstr RDP ; $session = $session.Split(",")[3] ; $session.Split('"')[1]

3. Start process: ``PsExec.exe -s -i 123 python my_script.py``.

.. _`this post on StackExchange`: https://serverfault.com/a/852877/368634
.. _`PsTools`: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec


`Ansible`_ has PsExec plugin that simplifies it. Playbook example:

.. _`Ansible`: https://github.com/ansible/ansible

::

---
- name: test ra module
hosts: *****
tasks:
- name: run GUI automation
win_psexec:
command: python pywinauto_example.py
executable: C:\Windows\PSTools\psexec.exe
interactive: yes
username: admin
password: ******
hostnames: ******


Windows Scheduler is also capable to start jobs with GUI interaction support.
There is easy way to schedule the task from ``cmd.exe`` once:
::

Schtasks /Create /tn my_task /tr c:\temp\my_task.bat /sc ONCE /st hh:mi:ss /sd yyyy/mm/dd


How To`s
Expand Down

0 comments on commit e69bb41

Please sign in to comment.