繁体   English   中英

自动卸载 Windows 应用程序

[英]Automation of uninstalling a Windows Application

我正在尝试使用 7z 卸载的 Vasily Ryabov 示例在 Windows 上卸载名为 BlueStacks App Player 的应用程序。

我收到错误:

C:\Users\ADMIN\PycharmProjects\untitled1\venv\Scripts\python.exe

C:/Users/ADMIN/PycharmProjects/untitled1/uninstall_software.py Traceback(最近一次调用最后):文件“C:/Users/ADMIN/PycharmProjects/untitled1/uninstall_software.py”,第 5 行,在 explorer = pywinauto.Application( ).connect(path='explorer.exe') 文件“C:\Users\ADMIN\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application.py”,第 1005 行,在连接 self.__warn_incorrect_bitness() 文件“C:\Users\ADMIN\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application.py”,第 1083 行,在 __warn_incorrect_bitness 中,如果 self.backend。名称 == 'win32' 和 self.is64bit():= is_x64_Python(): 文件 "C.\Users\ADMIN\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application,py ",第 1098 行。在 is64bit 中返回 handleprops.is64bitprocess(self:process) 文件 "C.\Users\ADMIN\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\handleprops,py",第 183 行。在 is64bitprocess phndl = win32api.OpenProcess(w in32con,MAXIMUM_ALLOWED, 0. process_id) pywintypes:error, (87, 'OpenProcess'. '参数不正确')

进程以退出代码 1 结束

代码是:

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_7z = ProgramsAndFeatures.FolderView.GetItem('BlueStacks App Player')
    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='BlueStacks App Player', class_name='#32770', active_only=True)
    if SevenZipInstaller.Exists():
        SevenZipInstaller.WaitNot('visible', timeout=20)

    if 'BlueStacks App Player' not in ProgramsAndFeatures.FolderView.Texts():
        print('OK')
finally:
    NewWindow.Close()

您必须以管理员身份启动脚本。 操作系统设计无法自动确认 UAC 确认(出于安全原因)。 所以你必须先禁用 UAC,然后按照这个答案以管理员身份重新启动脚本: https://stackoverflow.com/a/41930586/3648361

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM