2

I have a couple of applications that I am trying to uninstall from Windows 7 and Windows 8.1, using Python automation. Windows command lines will also work.

The programs appear on the Programs and Features list in the control panel. Clicking them and selecting uninstall will uninstall them without issue. Uninstalling manually by clicking through the Programs and Features menu works fine and easily.

The programs were installed using an EXE file rather than an MSI file.

What I have tried so far:

1)

wmic product get name

Using the command 'wmic product get name' shows a list of only some of the programs that are displayed on the 'Programs and Features' page. The programs I wish to uninstall are not listed.

2)

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall

The programs do not appear in the above registry location

3)

"Use pywinauto to open and manipulate the Programs and Features window directly."

The pywinauto module (or anything else that can find and manipulate window and button handles) does work to open and grab the Programs and Features window, but manipulating it fails. In particular, entering text into the search box fails, so the programs to uninstall cannot be selected.

4)

"Use the uninstall msi that came with the program."

There wasn't one.

5)

"Run the installer executable again."

That just updates the software, rather than remove it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Richard
  • 494
  • 7
  • 18
  • Could you please provide an example of program to install/uninstall? I can try to help with pywinauto approach. – Vasily Ryabov Aug 07 '15 at 07:54
  • Thanks, but I managed to find an alternate solution (not listed as an answer since it is highly specific to the programs I am using and not generally applicable). Both pywinauto and AutoIt had the same problems with manipulating the Programs and Features window on Windows 7; trying to enter text into the search box works intermittently at best. – Richard Aug 10 '15 at 08:58

1 Answers1

3

I wrote an uninstall example for 7-Zip using pywinauto 0.5.2. It works stable for me on both Windows 7 and Windows 8.1. I believe it can be useful for someone else.

Of course it's a demo example only because 7-Zip can be simply uninstalled by "wmic" command with corresponding parameters.

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()
Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • Traceback (most recent call last): File "C:\Users\arugupta\Desktop\Arushi\uninstall.py", line 38, in 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'} – Arushi gupta Sep 30 '18 at 19:33
  • 1
    Maybe `explorer.exe` starts too slow on your PC. It's possible to bypass using `connect(path='explorer.exe', timeout=20)`. – Vasily Ryabov Sep 30 '18 at 20:42
  • Getting the following error now: explorer = Application().Connect(path='explorer.exe', timeout=20) Traceback (most recent call last): File "uninstall1.py", line 7, in explorer = Application().Connect(path='explorer.exe', timeout=20) File "C:\Python27\lib\site-packages\pywinauto\__init__.py", line 50, in wrap return method(*args, **kwargs) File "C:\Python27\lib\site-packages\pywinauto\application.py", line 973, in connect self.__warn_incorrect_bitness() – Arushi gupta Oct 02 '18 at 13:33
  • File "C:\Python27\lib\site-packages\pywinauto\application.py", line 1051, in __warn_incorrect_bitness if self.backend.name == 'win32' and self.is64bit() != is_x64_Python(): File "C:\Python27\lib\site-packages\pywinauto\application.py", line 1066, in is64bit return handleprops.is64bitprocess(self.process) File "C:\Python27\lib\site-packages\pywinauto\handleprops.py", line 174, in is64bitprocess phndl = win32api.OpenProcess(win32con.MAXIMUM_ALLOWED, 0, process_id) pywintypes.error: (87, 'OpenProcess', 'The parameter is incorrect.') – Arushi gupta Oct 02 '18 at 13:33