Windows Services中的路径 [英] Path in Windows Services

查看:59
本文介绍了Windows Services中的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows应用程序中,我们将路径称为Application.StartUpPath .....
用同样的方式在Windows服务中提到路径...

In windows applications , we mention the path as Application.StartUpPath.....
In the same way how to mention the path in Windows Services...

推荐答案

首先,不要混淆启动路径和可执行文件路径.第一件事绝对是不可靠的,永远不应依赖.对于交互式应用程序,用户可以从任何地方启动应用程序.对于服务……我什至从不进行检查,但可能会有所不同.可执行路径是可靠的东西,仅记住您可以在其中(或某些子目录中)放置只读对象.

有不同的方法来执行此操作,但是结果有时取决于应用程序的托管方式,因此它们无法显示服务或Visual Studio托管的应用程序的正确路径.这是查找在所有情况下都使用的可执行路径的可移植可靠方法:

First, don''t mix up start-up path and executable path. First thing is absolutely unreliable and should never be relied upon. For interactive applications, the user can start application from anywhere. For services… I never even though of checking it up, but also might vary. Executable path is reliable thing, only remember that you can put read-only object there (or in some sub-directory).

There are different ways to do it, but the result sometimes depends on how application is hosted, so they fail to show correct path for a service or, say, application hosted by Visual Studio. Here is the portable reliable way of finding the executable path which I use in all cases:

string exeDirectory =
   System.IO.GetDirectoryName(
      System.Reflection.Assembly.GetEntryAssembly().Location);



-SA



—SA


不确定这是否是您所需要的,因为服务与应用程序完全不同,但是
not sure if this is what you need because services are quite different from apps but
AppDomain.CurrentDomain.BaseDirectory

可能正是您想要的?


这篇关于Windows Services中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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