专注、自由、分享

Live your dream and share your passion

  :: :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

使用Microsoft.NET平台开发的Windows Service Application,安装后运行的默认工作目录是"C:\Windows\System32",这样服务运行日志和其他的业务输出都将在该目录中,对业务系统来说这样的默认值非常不方便,需要修改该默认工作目录到应用程序的部署目录,经过N种方法的尝试,目前发现只有1中方法可行,即在服务入口方法中加入代码:

Environment.CurrentDirectory = System.AppDomain.CurrentDomain.BaseDirectory;

示例代码如下:

隐藏行号 复制代码 这是一段程序代码。
  1. using System;
    
  2. using System.Collections.Generic;
    
  3. using System.Linq;
    
  4. using System.ServiceProcess;
    
  5. using System.Text;
    
  6. 
    
  7. namespace Freemansoft.Csm.DbSynchronization
    
  8. {
    
  9.     static class Program
    
  10.     {
    
  11.         /// <summary>
    
  12.         /// The main entry point for the application.
    
  13.         /// </summary>
    
  14.         static void Main()
    
  15.         {
    
  16.             ServiceBase[] ServicesToRun;
    
  17.             ServicesToRun = new ServiceBase[] 
    
  18.             { 
    
  19.                 new Synchronization() 
    
  20.             };
    
  21.             Environment.CurrentDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
    
  22.             ServiceBase.Run(ServicesToRun);
    
  23.         }
    
  24.     }
    
  25. }
    
posted on 2011-07-27 19:00  我是柯南  阅读(993)  评论(0编辑  收藏  举报