0

I am trying to uninstall an application named BlueStacks App Player on Windows using the Vasily Ryabov example of 7z uninstall.

I'm getting the error:

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

C:/Users/ADMIN/PycharmProjects/untitled1/uninstall_software.py Traceback (most recent call last): File "C:/Users/ADMIN/PycharmProjects/untitled1/uninstall_software.py", line 5, in explorer = pywinauto.Application().connect(path='explorer.exe') File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application.py", line 1005, in connect self.__warn_incorrect_bitness() File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application.py", line 1083, in __warn_incorrect_bitness if self.backend.name == 'win32' and self.is64bit() != is_x64_Python(): File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application.py", line 1098, in is64bit return handleprops.is64bitprocess(self.process) File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\handleprops.py", line 183, in is64bitprocess phndl = win32api.OpenProcess(win32con.MAXIMUM_ALLOWED, 0, process_id) pywintypes.error: (87, 'OpenProcess', 'The parameter is incorrect.')

Process finished with exit code 1

The code is :

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()
Lee Yerin
  • 37
  • 4

1 Answers1

1

You must start the script as Administrator. UAC confirmation can't be automated by OS design (for security reason). So you have to disable UAC first, then follow this answer to restart the script as Administrator: https://stackoverflow.com/a/41930586/3648361

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • I'm still getting this error : `pywintypes.error: (87, 'OpenProcess', 'The parameter is incorrect.')` It's opening the explorer window and nothing happens after that. – Lee Yerin Jun 10 '20 at 07:21
  • 2
    Running script as Administrator means "right click on the script and choose "run as Administrator" menu item". User can be in admin group, but default running mode is not as Administrator. The same can be done for `cmd.exe` or set in the shortcut properties to always run as Admin. – Vasily Ryabov Jun 11 '20 at 03:04