Python Forum

Full Version: Automating Windows GUI applications
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
from pywinauto import application
app = application.Application()
app.start("Notepad.exe")

The above code launches a notepad.

But when I try to run this this .It throws and error and fails to launch the executable

from pywinauto import application
app = application.Application()
app.start("C:\Program Files\Microsoft Assessment and Planning Toolkit\bin\MapToolkit.exe")

Traceback (most recent call last):
File "C:\Users\km041320\AppData\Local\Continuum\anaconda3\lib\site-packages\pywinauto\application.py", line 1047, in start
start_info) # STARTUPINFO structure.
pywintypes.error: (2, 'CreateProcess', 'The system cannot find the file specified.')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\km041320\AppData\Local\Continuum\anaconda3\lib\site-packages\pywinauto\application.py", line 1052, in start
raise AppStartError(message)
pywinauto.application.AppStartError: Could not create the process "C:\Program Files\Microsoft Assessment and Planning Toolkiin\MapToolkit.exe"
Error returned by CreateProcess: (2, 'CreateProcess', 'The system cannot find the file specified.')
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.

You were warned on multiple occasions. I will lock this thread now and you are free to repost, using proper BBcode tags, as per forum rules
from pywinauto import application
app = application.Application()
app.start("Notepad.exe")
The above code launches a notepad.
But when I try to run this.It throws and error and fails to launch the executable

from pywinauto import application
app = application.Application()
app.start("C:\Program Files\Microsoft Assessment and Planning Toolkit\bin\MapToolkit.exe")
Error:
Traceback (most recent call last): File "C:\Users\ABCD\AppData\Local\Continuum\anaconda3\lib\site-packages\pywinauto\application.py", line 1047, in start start_info) # STARTUPINFO structure. pywintypes.error: (2, 'CreateProcess', 'The system cannot find the file specified.') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\ABCD\AppData\Local\Continuum\anaconda3\lib\site-packages\pywinauto\application.py", line 1052, in start raise AppStartError(message) pywinauto.application.AppStartError: Could not create the process "C:\Program Files\Microsoft Assessment and Planning Toolkiin\MapToolkit.exe" Error returned by CreateProcess: (2, 'CreateProcess', 'The system cannot find the file specified.')
Whit windows paths, don't use backslash. Use forward slash or raw-strings, e.g.
app.start("C:/Program Files/Microsoft Assessment and Planning Toolkit/bin/MapToolkit.exe")
or
app.start(r"C:\Program Files\Microsoft Assessment and Planning Toolkit\bin\MapToolkit.exe")
back-slash in combination with certain chars are escape sequences and have a different meaning
>>> app.start(r"C:\Program Files\Microsoft Assessment and Planning Toolkit\bin\MapToolkit.exe")
Traceback (most recent call last):
  File "C:\Users\ABCD\AppData\Local\Continuum\anaconda3\lib\site-packages\pywinauto\application.py", line 1047, in start
    start_info)                         # STARTUPINFO structure.
pywintypes.error: (740, 'CreateProcess', 'The requested operation requires elevation.')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\ABCD\AppData\Local\Continuum\anaconda3\lib\site-packages\pywinauto\application.py", line 1052, in start
    raise AppStartError(message)
pywinauto.application.AppStartError: Could not create the process "C:\Program Files\Microsoft Assessment and Planning Toolkit\bin\MapToolkit.exe"
Error returned by CreateProcess: (740, 'CreateProcess', 'The requested operation requires elevation.')
>>>

>>> app.start("C:/Program Files/Microsoft Assessment and Planning Toolkit/bin/MapToolkit.exe")
Traceback (most recent call last):
  File "C:\Users\km041320\AppData\Local\Continuum\anaconda3\lib\site-packages\pywinauto\application.py", line 1047, in start
    start_info)                         # STARTUPINFO structure.
pywintypes.error: (740, 'CreateProcess', 'The requested operation requires elevation.')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\km041320\AppData\Local\Continuum\anaconda3\lib\site-packages\pywinauto\application.py", line 1052, in start
    raise AppStartError(message)
pywinauto.application.AppStartError: Could not create the process "C:/Program Files/Microsoft Assessment and Planning Toolkit/bin/MapToolkit.exe"
Error returned by CreateProcess: (740, 'CreateProcess', 'The requested operation requires elevation.')

worked after opening cmd as admin
Thanks