I am trying to use CreateProcessA
to call an application under the %appdata%
directory.
For example, using the following:
CreateProcessA(
NULL, "%appdata%\myfile.exe", NULL, NULL, FALSE,
CREATE_NO_WINDOW, NULL, NULL, &sI, &pI
);
Do I need to use the complete path when calling myfile.exe
or is there someway I can use %appdata%
in the call to CreateProcessA
?
As stated in MSDN, and since you're passing NULL
to CreateProcessA
as a first argument, CreateProcessA
's 2nd argument : lpApplicationName
is playing the role of the command line to be executed. Unless lpApplicationName
points to an exe in a directory, the system will look for it in the following order
- 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.
Therefore, unless the second argument of CreateProcessA
is in the form {directory}/{executable_name}.{ext}
, you'll have to either :
As stated by Ben, take a look at ExpandEnvironmentStrings to modify PATH env variable.