• Advertisement
Sign in to follow this  

[.net] getting full path of my .exe

This topic is 4484 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
AppDomain.CurrentDomain.BaseDirectory

I don't think any of these (besides the Win32 call) will give you the hello.exe, though, just the path.

Share this post


Link to post
Share on other sites
This is very OS Specific...

For windows 32:As SiCrane mentioned, you want to use GetModuleFilename to do this. This will give you the desired behavior you are looking for. The syntax for that is:

DWORD GetModuleFileName(
HMODULE hModule,
LPTSTR lpFilename,
DWORD nSize
);


You will want to pass NULL as hModule, that represents the currently running process. make sure lpFilename points to an already created buffer zone. That means if you are creating your data on the heap, be sure to new it beforehand, and delete it afterward. nSize should be the number of bytes that your buffer can hold, it is important that this is set to the size of the buffer (or smaller) or you could easily have yourself a buffer overrun.

Also, for some reason i think there may be an undesired differing behaviour on Win95, though i may be thinking of the TOOLHELP and PSAPI functionality which i find i use quite often (remote process enumeration and such).

Anyways, good luck!
Richard

Share this post


Link to post
Share on other sites
Quote:
Original post by nagromo
AppDomain.CurrentDomain.BaseDirectory

I don't think any of these (besides the Win32 call) will give you the hello.exe, though, just the path.




=/

Share this post


Link to post
Share on other sites

FileInfo fi = new FileInfo(Application.ExecutablePath);
string appPath = fi.DirectoryName;

If you wanted just the directory.

[Edited by - Nypyren on November 10, 2005 2:41:19 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement