使用Python从控制面板自动卸载应用程序

时间:2018-09-30 19:51:33

标签: python

我想模拟从控制面板卸载应用程序。我正在使用以下代码,但出现错误。任何帮助表示赞赏。

from __future__ import print_function
import pywinauto
from pywinauto.application import Application

Application().Start(r'explorer.exe')
explorer = 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')
    explorer.WaitCPUUsageLower(threshold=5)

    item_7z = ProgramsAndFeatures.FolderView.GetItem('Adobe Photoshop Elements 2019')
    item_7z.EnsureVisible()
    item_7z.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)

    SevenZipInstaller = explorer.Window_(title='Adobe Photoshop Elements 2019', class_name='#32770', active_only=True)
    if SevenZipInstaller.Exists():
        SevenZipInstaller.WaitNot('visible', timeout=20)

    if 'Adobe Photoshop Elements 2019' not in ProgramsAndFeatures.FolderView.Texts():
        print('OK')
finally:
    NewWindow.Close()

错误:

C:\Users\arugupta\Desktop\Arushi>uninstall.py
C:\Users\arugupta\Desktop\Arushi\uninstall.py:5: DeprecationWarning: Method 
.Start() is deprecated, use .start() instead.
  Application().Start(r'explorer.exe')
C:\Users\arugupta\Desktop\Arushi\uninstall.py:6: DeprecationWarning: Method         
.Connect() is deprecated, use .connect() instead.
  explorer = Application().Connect(path='explorer.exe')
C:\Python27\lib\site-packages\pywinauto\application.py:1059: UserWarning:     64-bit application should be automated using 64-bit Python (you use 32-bit Python)
  UserWarning)

C:\Users\arugupta\Desktop\Arushi\uninstall.py:9: DeprecationWarning: Method .Window_() is deprecated, use .window() instead.
  NewWindow = explorer.Window_(top_level_only=True, active_only=True,     class_name='CabinetWClass')
Traceback (most recent call last):
  File "C:\Users\arugupta\Desktop\Arushi\uninstall.py", line 38, in <module>
    NewWindow.Close()
  File "C:\Python27\lib\site-packages\pywinauto\application.py", line 368,     in __getattribute__    
    ctrls = self.__resolve_control(self.criteria)    
  File "C:\Python27\lib\site-packages\pywinauto\application.py", line 249,     in __resolve_control
    raise e.original_exception
pywinauto.findwindows.ElementNotFoundError: {'active_only': True,     'class_name': 'CabinetWClass', 'process': 9816, 'top_level_only': True,         'backend': u'win32'}

我无法弄清楚为什么会出现此错误。我使用Swapy检查了文件浏览器的className,它与CabinetWClass相同。

0 个答案:

没有答案