Skip to content Skip to sidebar Skip to footer

How Does Createprocess Locate The Executable?

According to the docs, CreateProcess can be passed an executable name as first argument, or a command line as a second argument (from which the executable name will be extracted).

Solution 1:

You need to modify the environment of the current process if you want CreateProcess to see it. Currently, the subshell (whether included in the command line or requested via shell=True) is seeing your modified environment, but the direct invocation of CreateProcess is not.

Solution 2:

If I'm reading your question right, it sounds like you have an application named wc.exe in the folder that %HOMEDRIVE%%HOMEPATH%\SmallApps\GnuWin32\bin maps to. If that is the case, you would do better to set exe to the expanded version of %HOMEDRIVE%%HOMEPATH%\SmallApps\GnuWin32\bin\wc.exe. Since this path and executable name may end up containing spaces, it wouldn't hurt to wrap it in quotes as well.

In short, don't rely on the path search. Not only is it prone to errors, it's also a potential security hole.

Solution 3:

Thought of checking MSDN? CreateProcess documentation.

To quote one part of it:

The directory from which the application loaded. The current directory for the parent process. The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function.

Post a Comment for "How Does Createprocess Locate The Executable?"