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. }
      
  • 相关阅读:
    函数防抖与函数节流 封装好的debounce和throttle函数
    机顶盒
    getchar() putchar()
    【整】char、varchar、nchar、nvarchar的区别
    主机名
    主机
    java中的匿名内部类总结
    智能路由器又多一个玩家——乐视TV
    乐视开始折腾路由器,小米与极路由还会好过吗?
    带你认识什么是路由器
  • 原文地址:https://www.cnblogs.com/iamfreeman/p/2118723.html
Copyright © 2011-2022 走看看