我正在做一个服务方式运行的程序。
需要确定得到服务的所在的安装目录
我使用如下方法
System.IO.Directory.GetCurrentDirectory();
但是得到结果是:C:\WINDOWS\system32,并不是服务程序的安装目录。
我需要在程序开始运行的时候就得到安装目录,需要写日志文件用到的。

解决方案 »

  1.   

    是这个Application.StartupPath 
      

  2.   

    搞错~~~看看下面的代码,应该可以用。
    Assembly thisAssembly = Assembly.GetExecutingAssembly();
    dllPath = thisAssembly.Location;
      

  3.   

    dyshadow 你的方法看不明白哦,能解释一下么。
      

  4.   

    我的是服务程序不能添加Windows.Forms.dll的引用。
      

  5.   

    Assembly thisAssembly = Assembly.GetExecutingAssembly();//获取包含当前执行的代码的程序集
     dllPath = thisAssembly.Location;//获取已加载文件的位置  
      

  6.   

    Application.StartupPath  我无法找到这个方法,我是开发成了服务程序请大家注意,需要引用什么才能使用么,总之找不到。Assembly thisAssembly = Assembly.GetExecutingAssembly();//获取包含当前执行的代码的程序集 
    dllPath = thisAssembly.Location;//获取已加载文件的位置  
    不能添加Windows.Forms.dll的引用。
      

  7.   

    没有那么复杂吧,我就用这个
    AppDomain.CurrentDomain.SetupInformation.ApplicationBase