2024-10-29 06:00:00

获取我的.exe路径

我怎么能得到我的。exe路径,因为如果我复制我的。exe,我可以得到我的新路径?


当前回答

在Windows窗体项目中:

对于完整路径(包括文件名):string exePath = Application.ExecutablePath; string appPath = Application.StartupPath;

其他回答

在Windows窗体项目中:

对于完整路径(包括文件名):string exePath = Application.ExecutablePath; string appPath = Application.StartupPath;

此外:

AppDomain.CurrentDomain.BaseDirectory
Assembly.GetEntryAssembly().Location

第一个是应用程序可执行文件的目录。小心!它可以在运行时更改。

第二个,将是运行代码的程序集(.dll)的目录。

在visualstudio 2008中,你可以使用以下代码:

   var _assembly = System.Reflection.Assembly
               .GetExecutingAssembly().GetName().CodeBase;

   var _path = System.IO.Path.GetDirectoryName(_assembly) ;
System.Reflection.Assembly.GetEntryAssembly().Location;