Mega Code Archive

 
Categories / Delphi / Ide Indy
 

How to obtain the path to your program at runtime

Title: How to obtain the path to your program at runtime As most of you know the method MyFileName := Applicatoin.ExecName; to get the filename (incl. path) to the current executable (exe or dll). Well, this is ok but doesn't work for things like service-apps, controlpanel-apps, web-apps, etc. as the application object of thouse doesn't have the ExecName property. A function which works in every case is MyFileName := ParamStr(0); You're right! It's the command line parameter number zero. This is the way Windows does it. If you'd like to get the path to your program at runtime your can do something like: MyFilePath := ExtractFilePath(ParamStr(0));