Getting path of .exe from a dll

  • Thread starter Thread starter MarkMurphy
  • Start date Start date
M

MarkMurphy

Within a class that is implented in a called DLL is it possible to get
the path of the executable that is currently making use of that DLL?
This call returns the path of the dll:

Assembly.GetExecutingAssembly().GetName().CodeBase;

Mark
 
If you are inside a DLL method that you know was called by that EXE
directly, you can try Assembly.GetCallingAssembly()
Otherwise you will need to P/Invoke GetModuleFileName

[DllImport("coredll")]
extern static int GetModuleFileName( IntPtr hModule, StringBuilder
lpFilename, int nSize);

string GetCurrentProcessName()
{
int MaxPath = 256;
StringBuilder sb = new StringBuilder(MaxPath);
GetModuleFileName(IntPtr.Zero, sb, MaxSize);
return sb.ToString();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

read xml file from application folder 7
how to get the path ? 3
Get Filename of base exe 1
Version of seperate dll 3
Application path 12
Load unmanaged DLL in runtime 6
Assembly.GetExecutingAssembly(). 3
Path of dll 2

Back
Top