如何创建Python脚本来自动执行软件安装? [英] How to create a Python script to automate software installation?

查看:569
本文介绍了如何创建Python脚本来自动执行软件安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动化软件安装过程.情况如下:

I want to automate the software installation process. The scenario is as follows:

运行安装文件.在第一个屏幕上,接下来有两个按钮,请取消.单击下一步"时,将转到具有两个按钮的下一步"屏幕,下一步",取消",并且需要一些输入数据.提供详细信息后,它将显示完成"或取消"按钮.

Run the installation file. On first screen it has two buttons next, cancel. On click of next it goes to next screen having two buttons, next, cancel and some input data is required. After details are provided, it will show finish or cancel button.

我想编写一个Python脚本来自动执行此活动.它应该识别按钮并单击它.它应该在需要的地方输入数据并完成安装.要实现此功能:

I want to write a Python script that would automate this activity. It should identify the button and click it. It should enter the data wherever required and finish the installation. To achieve this functionality:

  1. 是否需要Python API?
  2. 一些代码示例或教程的链接也要使用.

示例图片:

推荐答案

正如Rawing所述,pywinauto是Windows安装程序的不错选择.这是不错的示例视频: http://pywinauto.github.io/

要等待下一页,请使用以下内容:app.WizardPageTitle.wait('ready')
安装程序完成后:app.FinishPage.wait_not('visible')
对于编辑框输入:app.WizardPage.Edit.type_keys('some input path', with_spaces=True)
对于按钮单击,我建议使用click_input()作为更可靠的方法.

如果要在许多计算机上自动安装该应用程序,则可以创建远程桌面或VNC会话,并在该会话中运行Python脚本的本地副本.只是不要最小化RDP或VNC窗口以防止GUI上下文丢失.失去焦点是安全的,您可以在另一个窗口中继续在主机上工作,而不会影响远程安装.


FastStone Image Viewer 4.6的简易安装脚本示例:

As Rawing mentioned, pywinauto is good choice for Windows installer. Here is nice sample video: http://pywinauto.github.io/

For waiting next page use something like that: app.WizardPageTitle.wait('ready')
When installer finished: app.FinishPage.wait_not('visible')
For edit box input: app.WizardPage.Edit.type_keys('some input path', with_spaces=True)
For button clicks I'd recommend click_input() as more reliable method.

If you want to install the app on many machines automatically, you can create Remote Desktop or VNC session and run local copy of the Python script inside that session. Just do not minimize RDP or VNC window to prevent GUI context loss. Losing focus is safe and you can continue your work on master machine in another window without affecting remote installation.


Example of easy install script for FastStone Image Viewer 4.6:

import os
from pywinauto.application import Application

fsv = Application(backend="win32").start("FSViewerSetup46.exe")

fsv.InstallDialog.NextButton.wait('ready', timeout=30).click_input()
fsv.InstallDialog.IAgreeRadioButton.wait('ready', timeout=30).click_input()
fsv.InstallDialog.Edit.Wait('ready', timeout=30).type_keys(os.getcwd() + "\FastStone Image Viewer", with_spaces=True)
fsv.InstallDialog.InstallButton.wait('ready', timeout=30).click_input()
fsv.InstallDialog.FinishButton.wait('ready', timeout=30).click_input()

这篇关于如何创建Python脚本来自动执行软件安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆