Somehow, at every client I need a function like GetExecutablePath.
Maybe you do too, so here is the code that I adapted a long time ago from the Delphi 2006 RTL:
using System; using System.Diagnostics; using System.Reflection; namespace bo.Reflection { public class AssemblyHelper { public static string GetExecutablePath() { // borrowed from D2006\source\dotNet\rtl\Borland.Delphi.System.pas function ParamStr(): string result; Assembly entryAssembly = Assembly.GetEntryAssembly(); if (null != entryAssembly) { result = entryAssembly.Location; } else { Process currentProcess = Process.GetCurrentProcess(); ProcessModule mainModule = currentProcess.MainModule; result = mainModule.FileName; } return result; } } }
Enjoy :-)
–jeroen