Windows 服务安装 - 当前目录 [英] Windows Service installation - current directory

查看:41
本文介绍了Windows 服务安装 - 当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与我的上一个有关.我已经用 C# 编写了一个服务,我需要使它的名称动态化并从配置文件中加载名称.问题是调用服务安装程序时的当前目录是 net framework 4 目录,而不是我的程序集所在的目录.

this question is related to my previous one . I've written a service in C# and I need to make it's name dynamic and load the name from configuration file. The problem is that current directory while the service installer is invoked is the net framework 4 directory instead of the one that my assembly sits in.

使用线路(这有助于解决同样的问题,但服务已经在运行)System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

Using the line (which helps with the same problem, but while the service is already running) System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

设置目录为

C:\Windows\Microsoft.NET\Framework\v4.0.30319

这也是初始值.

如何获得正确的路径?

推荐答案

试试这个:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

这篇关于Windows 服务安装 - 当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆