string exeDir = Application.ExecutablePath;//
//string exeDir1 = System.IO.Directory.GetCurrentDirectory();
string exeDir2 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
string exeDir3 = System.AppDomain.CurrentDomain.BaseDirectory;//
//string exeDir4 = System.Environment.CurrentDirectory;
string exeDir5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
string exeDir6 = System.Windows.Forms.Application.StartupPath;
string exeDir7 = System.Windows.Forms.Application.ExecutablePath;//
其中注释的两行,在正常情况下运行时可以获取运行的目录的,但如果是软件开机自启动,获取的目录将不是软件运行目录,而是win64目录。
以下为没有注释的代码输出结果。
D:\Program Files\shutdown\Shutdown.exe
D:\Program Files\shutdown\Shutdown.exe
D:\Program Files\shutdown\
D:\Program Files\shutdown\
D:\Program Files\shutdown
D:\Program Files\shutdown\Shutdown.exe