Executing programs in your PATH

This is a discussion on Executing programs in your PATH within the Windows Programming forums, part of the Platform Specific Boards category; Hello,
I'm using C++ Builder and trying to run a program with CreateProcess. For example:
Code:
if ( !CreateProcess("cmd", NULL, ...

This compiles fine, however it doesn't run cmd.exe. (having "cmd.exe" as the argument doesn't help either). The MessageBox with the error is executed.

If I use system("cmd"); it works just fine. This is the same for other programs that I have in my PATH, for example my gcc compiler. Is there any way I can run these with CreateProcess without specifying the full path? Because CreateProcess gives you a lot more control, like a process handle and ID that you can use with WaitForSingleObject() etc...

The command line to be executed. The maximum length of this string is 32,768 characters, including the Unicode terminating null character. If lpApplicationName is NULL, the module name portion of lpCommandLine is limited to MAX_PATH characters.

... *SNIP* ...

If the file name does not contain a directory path, the system searches for the executable file in the following sequence:

1. The directory from which the application loaded.
2. The current directory for the parent process.
3. The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
4. 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.
5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
6. 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.