获取程序当前文件夹 c#
MessageBox.Show("Environment.CurrentDirectory :" + Environment.CurrentDirectory
+ "\r\n Application.ExecutablePath " + Application.ExecutablePath
+ "\r\n Directory.GetCurrentDirectory() " + Directory.GetCurrentDirectory()
+ "\r\n AppDomain.CurrentDomain.BaseDirectory " + AppDomain.CurrentDomain.BaseDirectory
+ "\r\n Application.StartupPath " + Application.StartupPath) ;
+ "\r\n Application.ExecutablePath " + Application.ExecutablePath
+ "\r\n Directory.GetCurrentDirectory() " + Directory.GetCurrentDirectory()
+ "\r\n AppDomain.CurrentDomain.BaseDirectory " + AppDomain.CurrentDomain.BaseDirectory
+ "\r\n Application.StartupPath " + Application.StartupPath) ;
普通运行时, 如图:
将程序设置为开机自动启动时, 如图:
开机自启程序, 读取程序文件夹下面的文件, 要写具体路径, 默认当前路径是当前用户文件夹, 会读不到文件的.
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; // 可以得到当前主程序完整路径