python桌面应用_python 桌面应用程序自动化工具(pywinauto)

【实例简介】桌面应用程序自动化工具

【实例截图】

68e32315b8b8a5911b87594458e067c5.png

660502f6e0607f6c6417f6bf9bdee710.png

【核心代码】

"""

Uninstall script for 7zip 9.20 (64-bit)

Requirements:

- Win7 or Win8.1 x64, 64-bit Python

- pywinauto 0.5.2

- UAC is fully disabled

"""

from __future__ import print_function

import pywinauto

pywinauto.Application().Start(r'explorer.exe')

explorer = pywinauto.Application().Connect(path='explorer.exe')

# Go to "Control Panel -> Programs and Features"

NewWindow = explorer.window(top_level_only=True, active_only=True, class_name='CabinetWClass')

try:

NewWindow.AddressBandRoot.click_input()

NewWindow.type_keys(r'Control Panel\Programs\Programs and Features{ENTER}',

with_spaces=True, set_foreground=False)

ProgramsAndFeatures = explorer.window(top_level_only=True, active_only=True,

title='Programs and Features', class_name='CabinetWClass')

# wait while the list of programs is loading

explorer.wait_cpu_usage_lower(threshold=5)

item_7z = ProgramsAndFeatures.FolderView.get_item('7-Zip 9.20 (x64 edition)')

item_7z.ensure_visible()

item_7z.click_input(button='right', where='icon')

explorer.PopupMenu.menu_item('Uninstall').click()

Confirmation = explorer.window(title='Programs and Features', class_name='#32770', active_only=True)

if Confirmation.Exists():

Confirmation.Yes.click_input()

Confirmation.wait_not('visible')

WindowsInstaller = explorer.window(title='Windows Installer', class_name='#32770', active_only=True)

if WindowsInstaller.Exists():

WindowsInstaller.wait_not('visible', timeout=20)

SevenZipInstaller = explorer.window(title='7-Zip 9.20 (x64 edition)', class_name='#32770', active_only=True)

if SevenZipInstaller.Exists():

SevenZipInstaller.wait_not('visible', timeout=20)

if '7-Zip 9.20 (x64 edition)' not in ProgramsAndFeatures.FolderView.texts():

print('OK')

finally:

NewWindow.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值