• 如果修改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. }
      
  • 相关阅读:
    Cassandra
    【CISCO强烈推荐】生成树 《路由协议》 卷一二 拥塞:网络延迟 阻塞:进程中 MTU QS:服务质量 OSPF RIP ISIS BGP 生成树 《路由协议》 卷一二
    m*n matrix min rank square matrix
    Moving Computation is Cheaper than Moving Data
    SASL mechanism
    一阶 斜率 二阶 原函数的粗糙度 roughness
    Linux 虚拟内存盘
    Bloom Filters
    R Tree
    释放内存
  • 原文地址:https://www.cnblogs.com/iamfreeman/p/2118723.html
Copyright © 2020-2023  润新知