Windows服务-获取当前目录 [英] Windows service - get current directory
本文介绍了Windows服务-获取当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Windows服务,应该在其当前目录中查找配置文件.
I have a Windows service that should look for a configuration file in its current directory.
所以我使用 directory.getcurrentdirectiry()
,但是我返回的不是服务目录,而是
So I use directory.getcurrentdirectiry()
but instead of the service directory I get back
c:\windows\system32
是否知道为什么以及如何获取服务目录?
Any idea why and how should I get the service directory?
推荐答案
不要使用 Directory.GetCurrentDirectory()
.返回 C:\ Windows \ System32 时,我遇到了完全相同的问题.改用它:
Don't use Directory.GetCurrentDirectory()
. I had the same exact problem with C:\Windows\System32 being returned. Use this instead:
Path.GetDirectoryName(Application.ExecutablePath);
这篇关于Windows服务-获取当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文