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.
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()