如何在Windows服务中获取.ini文件的路径? [英] How to get path of .ini file in windows service?

查看:111
本文介绍了如何在Windows服务中获取.ini文件的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点怀疑。我想从我安装项目的文件夹中获取配置文件路径,它可能是任何驱动器路径。目前我在程序中提供硬编码路径,但在不同系统中安装时会出错。



我试过以下,



string f = Path.Combine(Directory.GetCurrentDirectory(), hr.ini);



但是在安装服务后它返回如下路径,



C :\ Windows \ system32 \ hr.ini。



但是我想要它存在的实际路径是C:\ProgramFiles \\ \\ setupject \hr.ini。



所以请建议我任何例子。

谢谢

I have a small doubt. I want to get my configue file path from folder where i install my project it may be any drive path. currently i give path hardcoded in program but at time of installation in different system it would give error.

I tried following ,

string f = Path.Combine(Directory.GetCurrentDirectory(), "hr.ini");

but after installing service it returns path like below,

"C:\Windows\system32\hr.ini. "

but i want its actual path where this file is present which is "C:\ProgramFiles\SetupProject\hr.ini".

so please suggest me any examples.
thanks

推荐答案

您可以使用AppDomain路径,如下所示:



You can use the AppDomain path, like so:

var f = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "hr.ini");


这篇关于如何在Windows服务中获取.ini文件的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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