Search code examples
pywinauto

getting error as pywinauto.application.AppStartError: Could not create the process "mmc printmanagement.msc"


I am trying to open printmanagement.msc using the below code. But getting error.

My code:

from pywinauto.application import Application
Application().start(r'mmc printmanagement.msc')

Error:

pywinauto.application.AppStartError: Could not create the process "mmc printmanagement.msc"
Error returned by CreateProcess: (740, 'CreateProcess', 'The requested operation requires elevation.')

Solution

  • Elevation means "running as Administrator". You should start Python process as Administrator (or your IDE, or cmd.exe before starting python.exe in a console). The parent process for mmc.exe must run as Administrator.

    Another way to allow automatic elevation (if Python is not a privileged process):

    Application().start(r'cmd.exe /c mmc.exe printmanagement.msc', wait_for_idle=False)
    

    And then you need to connect to child mmc.exe process this way.

    app = Application(backend='win32').connect(path='mmc.exe')
    # or using backend="uia" whatever is better
    

    Because launcher process cmd.exe exits immediately. pywinauto can't detect and handle spawned child processes automatically but we have such feature request.