asdfasfasdf

如何获取Windows服务对应程序的所在目录?

在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

posted on 2007-03-07 11:23  明达  阅读(677)  评论(0)    收藏  举报

导航