Click to See Complete Forum and Search --> : How to obtain absolute file pathname of a process?
josedsilva
April 26th, 2005, 12:29 PM
Hi,
I want to obtain the absolute directory pathname of a process. The cmdLn argument in WinMain() only provides command line arguments passed to the process when it is started. It however, does not pass the pathname of the process. In console based programming, the argv[0] parameter would specify the process pathname. But how is this done in WIN32 programming?
Thanks,
Jose
SirNotApearingOnThisForum
April 26th, 2005, 12:44 PM
char file[MAX_PATH];
HINSTANCE hint;
hint = GetModuleHandle(NULL);
GetModuleFileName(hint, file, MAX_PATH);
file[strlen(file)] = 0;
genossa
April 27th, 2005, 09:10 AM
Hello!
GetProcessImageFileName (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/getprocessimagefilename.asp) can also obtain complete process filename.
Unfortunately, it requires Windows XP only :thumbd:
Hennadii.
NoHero
April 27th, 2005, 10:01 AM
I want to obtain the absolute directory pathname of a process. The cmdLn argument in WinMain() only provides command line arguments passed to the process when it is started. It however, does not pass the pathname of the process. In console based programming, the argv[0] parameter would specify the process pathname. But how is this done in WIN32 programming?
As an addition to the CmdLine argument of WinMain you can also use GetCommandLine() function. Which will also retrieve the absolute path name of the module you are in.
But the best solution have been posted by SirNotApearingOnThisForum. You should go for this.
josedsilva
April 28th, 2005, 07:36 PM
Thanks guys,
your suggestions worked. I prefer to use the code given by SirNotApearingOnThisForum. That was a good one.
Thanks guys.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.