I want to remotely execute another application from my C++ program. So far I played along with the CreateProcess(...) function and it works just fine.
The problem ho
The directories of the programs you can run from start -> run are added to the PATH variable. You can add the folder your program is to the PATH and then use CreateProcess(). However, you say you don't know the directory, so you probably can't do this.
Do you know a partial path? For example, do you know that your exe will always be in C:\something\something\ or a subfolder of this path? If so, look up FindFirst() and FindNext() to list all the files in that directory and search for your exe, then use CreateProcess() when you find your exe.
http://msdn.microsoft.com/en-us/library/aa365200%28VS.85%29.aspx shows how to list files in a directory. You will have to modify it to also search subdirectories (for example, make a recursive function).
Launching programs and counting on PATH in any way is considered insecure coding. System PATHs may get polluted with locations that aren't secured properly such as a network drive. The best way to launch an application is to launch the executable from exactly where it stands and set the CWD to the location of the executable as installed. Otherwise you could be launching malicious code.
Most likely some combination of information from here will help get the location correctly: Detecting installed programs via registry
Greg
If you are using CreateProcess like this:
CreateProcessA( "winword.exe", .... );
then the PATH variable will not be used. You need to use the second parameter:
CreateProcessA( NULL, "winword.exe", .... );
See http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx for details.
You're looking for ShellExecute()
. That will even work if you pass it a proper URL, just like the Run menu.