获取Windows服务下当前路径的方法

获取Windows服务下当前路径的方法

获取当前运行程序路径 包含exe
Assembly.GetExecutingAssembly().Location;
D:xxxxxxinDebugxx.exe

获取当前运行程序路径 包含exe
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
D:xxxxxxinDebugxx.exe

获取该进程从中启动的目录
System.Environment.CurrentDirectory;
C:WINDOWSsystem32Logs

获取应用程序的当前工作目录
System.IO.Directory.GetCurrentDirectory();
C:WINDOWSsystem32

获取程序的基目录
System.AppDomain.CurrentDomain.BaseDirectory;
D:xxxxxxinDebug

获取启动了应用程序的可执行文件的路径
System.Windows.Forms.Application.StartupPath;
D:xxxxxxinDebug
原文地址:https://www.cnblogs.com/zhaochengshen/p/10656191.html