Tech Support > Microsoft Windows > Development Resources > Finding the path & filename of a running program
Finding the path & filename of a running program
Posted by Jeffrey Adler on December 9th, 2007


Hi all-

I am writing a program that would like to determine what path and specific
directory it was run from.

Any suggestions?

Thanks.


Posted by Sylvain on December 9th, 2007


Jeffrey Adler wrote on 09/12/2007 22:30:
"run from" is quite imprecise.

does it mean "what is the current directory" or "what is the directory
hosting the running exec" ?

assuming:
TCHAR path [_MAX_PATH];
TCHAR drive[_MAX_DRIVE];
TCHAR drcty[_MAX_DIR];

for the first use: GetCurrentDirectory(path, _MAX_PATH);

for the later use: GetModuleFileName(instance, path, _MAX_PATH);
where 'instance' is the HINSTANCE member receveid by the main funtion.
then something like:
_splitpath(path, drive, drcty, NULL, NULL);
sprintf(path, "%s%s", drive, drcty);


Sylvain.


Posted by Christian ASTOR on December 9th, 2007


Jeffrey Adler wrote:

e.g. GetModuleFileNameEx()

Posted by Jeffrey Adler on December 10th, 2007



"Sylvain" <noSpam@mail.net> wrote in message
news:475c6e83$0$27402$ba4acef3@news.orange.fr...
I was looking for the latter. Thanks!

Jeff.




Similar Posts