通过控制面板使用pywinauto卸载Windows应用程序

时间:2017-11-13 10:39:24

标签: python-3.x pywinauto pyautogui

您好我正在尝试在我的Windows机器中卸载名为test5的应用程序 使用 Vasily Ryabov 7z uninstall的例子

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.ClickInput()
    NewWindow.TypeKeys(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 list of programs is loading
    explorer.WaitCPUUsageLower(threshold=5)

    item_test = ProgramsAndFeatures.FolderView.GetItem("TEST5")
    item_test.EnsureVisible()
    item_test.ClickInput(button='right', where='icon')
    explorer.PopupMenu.MenuItem('Uninstall').Click()

    Confirmation = explorer.Window_(title='Programs and Features', class_name='#32770', active_only=True)
    if Confirmation.Exists():
        Confirmation.Yes.ClickInput()
        Confirmation.WaitNot('visible')

    WindowsInstaller = explorer.Window_(title='Windows Installer', class_name='#32770', active_only=True)
    if WindowsInstaller.Exists():
        WindowsInstaller.WaitNot('visible', timeout=20)

    TestInstaller = explorer.Window_(title="TEST5", class_name='#32770', active_only=True)
    if  TestInstaller.Exists():
        TestInstaller.WaitNot('visible', timeout=20)

    if "TEST5" not in ProgramsAndFeatures.FolderView.Texts():
        print('OK')
finally:
    NewWindow.Close()

以下错误。

> E:\Program
> Files\python\lib\site-packages\pywinauto\application.py:1036:
> UserWarning: 64-bit application should be automated using 64-bit
> Python (you use 32-bit Python)   UserWarning) Traceback (most recent
> call last):   File "E:/PYTHON/uninstall.py", line 17, in <module>
>     item_aperio = ProgramsAndFeatures.FolderView.GetItem("TEST5")   File "E:\Program
> Files\python\lib\site-packages\pywinauto\controls\common_controls.py",
> line 834, in get_item
>     return _listview_item(self, item_index, subitem_index)   File "E:\Program
> Files\python\lib\site-packages\pywinauto\controls\common_controls.py",
> line 88, in __init__
>     self.item_index = self._as_item_index(item_index)   File "E:\Program
> Files\python\lib\site-packages\pywinauto\controls\common_controls.py",
> line 101, in _as_item_index
>     index = int((self.listview_ctrl.texts().index(item) - 1) / self.listview_ctrl.column_count()) ValueError: 'TEST5' is not in list

0 个答案:

没有答案