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. }
      
  • 相关阅读:
    ArcGIS Server JavaScript API 各命名空间的含义【转】
    python datetime 转timestamp
    python re 里面match 和search的区别
    django 两种创建模型实例的方法
    delete old data in elasticsearch
    iptables做nat网络地址转换
    zabbix trapper items
    pssh远程执行命令的利器
    gentoo 下安装lamp
    xshell密钥登录服务器
  • 原文地址:https://www.cnblogs.com/iamfreeman/p/2118723.html
Copyright © 2011-2022 走看看