views:

139

answers:

3

Hey folks,

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 however is that I need the full path of the other program but I do not know the directory of it. So what I want is that I just have to enter the name of the other program, like when you type "cmd" or "winword" into Run... it opens the corresponding programs.

Thanks in advance, Russo

+2  A: 

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.

anon
+3  A: 

You're looking for ShellExecute(). That will even work if you pass it a proper URL, just like the Run menu.

MSalters
+1  A: 

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).

IVlad