zoukankan      html  css  js  c++  java
  • 如果修改Windows服务应用程序工作目录?

    使用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. }
      
  • 相关阅读:
    旅行锦囊
    生活智慧
    育儿锦囊
    新婚置办
    软件开发心得
    64位sql server2005安装
    Struts学习心得
    Spring学习心得
    Oracle补习班第十天
    Python----文件操作
  • 原文地址:https://www.cnblogs.com/iamfreeman/p/2118723.html
Copyright © 2011-2022 走看看