查看文章 |
如何获取Windows服务对应程序的所在目录?
2008-01-18 13:21
在WinForm程序中,通常会采用Environment.CurrentDirectory来获取应用程序的当前目录,可是在Windows服务中,这种方式获取的是C:\Windows\System32,而我的服务是安装在D:\ABC目录下的,服务程序的名称为Test.exe。 可以采用以下方式: System.AppDomain.CurrentDomain.BaseDirectory获取的结果为:d:\abc\ System.Reflection.Assembly.GetExecutingAssembly().Location获取的结果为:d:\abc\Test.exe |