[python-win32] win32process.CreateProcess: '%1 is not a valid Win32 application.'

Niko Pasanen niko at pasanen.me
Wed Dec 9 05:12:34 EST 2020


Dennis, Eryk,

Thank you for your responses. The results for assoc and ftype are the same
on my machine (should be tested on person C's pc, too).

The space in filepath was one of my first guesses, but unfortunately I was
not able to reproduce the error by putting a space in the filepath. But as
Eryk you pointed out, there must be a file with a matching filename in
order to get an error. This would explain why it is not reproducible.

Here are some of my test results:

Used test code
===========
from pathlib import Path
import win32process  # from pywin32


(h_process, _, dw_process_id, _) = win32process.CreateProcess(
    None,  # module name
    r"C:\tmp\first second\some.exe" ,
    None,  # Process handle not inheritable.
    None,  # Thread handle not inheritable.
    0,  # Set handle inheritance to FALSE.
    0,  # Creation flags.
    None,  # Use parent's environment block.
    None,  # If None - use parent's starting directory.
    win32process.STARTUPINFO(),
)  # STARTUPINFO structure.


Test  1
======
- Create broken exe with notepad (empty file)
- Broken exe at: C:\tmp\first.exe (or C:\tmp\first without .exe)
- Working exe at C\tmp\first second\some.exe
-> The broken exe is found first:

Traceback (most recent call last):
  File ".\testfix.py", line 5, in <module>
    (h_process, _, dw_process_id, _) = win32process.CreateProcess(
pywintypes.error: (193, 'CreateProcess', '%1 is not a valid Win32
application.')


Test 2
=====
- Same as Test 1, but use quoted string as the lpCommandLine (r'"C:\tmp\first
second\some.exe"')
-> The  C\tmp\first second\some.exe starts without problems.

So the problem might be that on the Person C's computer, there is actually
a file called "first" that is creating the error. The reason why I was
using win32process.CreateProcess like this was that I'm actually using
pywinauto, which uses  win32process.CreateProcess. I'll have to still test
this, but apparently this will fix some possible bugs. Thank you!

 - Niko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-win32/attachments/20201209/0a12e2eb/attachment.html>


More information about the python-win32 mailing list