Windows 从程序和功能自动卸载

Windows 从程序和功能自动卸载,windows,python-2.7,uninstallation,pywinauto,addremoveprograms,Windows,Python 2.7,Uninstallation,Pywinauto,Addremoveprograms,我有两个应用程序,我正试图使用Python自动化从Windows 7和Windows 8.1中卸载。Windows命令行也可以工作 这些程序显示在控制面板的“程序和功能”列表中。单击它们并选择卸载将卸载它们而不会出现问题。通过单击“程序和功能”菜单手动卸载,效果良好且轻松 这些程序是使用EXE文件而不是MSI文件安装的 到目前为止,我所尝试的: (一) 使用命令“wmic product get name”仅显示“程序和功能”页面上显示的部分程序的列表。我希望卸载的程序未列出 (二) 这些程序不

我有两个应用程序,我正试图使用Python自动化从Windows 7和Windows 8.1中卸载。Windows命令行也可以工作

这些程序显示在控制面板的“程序和功能”列表中。单击它们并选择卸载将卸载它们而不会出现问题。通过单击“程序和功能”菜单手动卸载,效果良好且轻松

这些程序是使用EXE文件而不是MSI文件安装的

到目前为止,我所尝试的:

(一)

使用命令“wmic product get name”仅显示“程序和功能”页面上显示的部分程序的列表。我希望卸载的程序未列出

(二)

这些程序不显示在上述注册表位置

(三)

“使用pywinauto直接打开和操作“程序和功能”窗口。”

pywinauto模块(或任何其他可以找到并操作窗口和按钮句柄的模块)确实可以打开并抓取“程序和功能”窗口,但操作失败。特别是,在搜索框中输入文本失败,因此无法选择要卸载的程序

(四)

“使用程序附带的卸载msi。”

没有

(五)

“再次运行安装程序可执行文件。”

这只是更新软件,而不是删除它。

我使用pywinauto 0.5.2编写了一个。它在Windows7和Windows8.1上对我来说工作稳定。我相信它对其他人有用

当然,这只是一个演示示例,因为7-Zip可以通过带有相应参数的“wmic”命令简单地卸载

from __future__ import print_function
import pywinauto

pywinauto.Application(backend="win32").start(r'explorer.exe')
explorer = pywinauto.Application(backend="win32").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 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()

你能提供一个安装/卸载程序的例子吗?我可以尝试帮助pywinauto方法。谢谢,但我设法找到了另一种解决方案(未作为答案列出,因为它非常特定于我使用的程序,并且不普遍适用)。pywinauto和AutoIt在操作Windows7上的程序和功能窗口时都有相同的问题;尝试在搜索框中输入文本最多只能间歇工作。回溯(最近一次调用最后一次):文件“C:\Users\arugupta\Desktop\Arushi\uninstall.py”,第38行,在NewWindow中。关闭()文件“C:\Python27\lib\site packages\pywinauto\application.py”,第368行,在getattribute ctrls=self.\uu resolve\u control(self.criteria)文件中“C:\Python27\lib\site packages\pywinauto\application.py”,第249行,在uu resolve\u控件中引发e.original\u异常pywinauto.findwindows.ElementNotFoundError:{'active_only':True,'class_name':'CabinetWClass','process':9816,'top_level_only':True,'backend':u'win32'}可能
explorer.exe
在您的电脑上启动太慢。可以使用
connect(path='explorer.exe',timeout=20)
绕过。现在获取以下错误:explorer=Application().connect(path='explorer.exe',timeout=20)回溯(上次调用):explorer=Application()中的文件“uninstall1.py”,第7行.Connect(path='explorer.exe',timeout=20)文件“C:\Python27\lib\site packages\pywinauto_init_uu.py”,第50行,在wrap返回方法(*args,**kwargs)文件“C:\Python27\lib\site packages\pywinauto\application.py”,第973行,在Connect self中。\uu警告\u bitness()文件“C:\Python27\lib\site packages\pywinauto\application\application.py”,第1051行,如果self.backend.name=='win32'和self.is64位()!=is_x64_Python():文件“C:\Python27\lib\site packages\pywinauto\application.py”,第1066行,在IS64位返回handleprops中。IS64位进程(self.process)文件“C:\Python27\lib\site packages\pywinauto\handleprops.py”,第174行,在IS64位进程phndl=win32api.OpenProcess(允许的最大值,0,进程id)pywintypes.error:(87,“OpenProcess”,“参数不正确”。)
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall
from __future__ import print_function
import pywinauto

pywinauto.Application(backend="win32").start(r'explorer.exe')
explorer = pywinauto.Application(backend="win32").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 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()