在C#中找到安装程序路径

编程入门 行业动态 更新时间:2024-10-28 10:26:13
本文介绍了在C#中找到安装程序路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在VS2008中,我编写了一个c#服务,一个安装程序,并创建了一个安装程序包来进行安装.该服务需要加载一个xml文件才能运行.将此文件放在VS安装项目提供的各种文件系统文件夹中的最佳位置是什么,然后如何从代码中引用这些路径?

In VS2008 I have writen a c# service, an installer and created a setup package to install it. The service needs to load an xml file to operate. Where is the best place to put this file in the various filesystem folders offered by the VS setup project, and how do I then refer to these paths from my code?

谢谢

[我应该指出,该服务以LocalService的身份运行,这意味着即使使用了为所有用户安装",也无法访问VS安装项目中用户的应用程序数据文件夹"项提供的applicationdata文件夹.在安装过程中.我可以轻松解决这个问题,但想了解最佳做法]

[I should point out the the service runs as LocalService, which means that the applicationdata folder offered by the "User's Application Data Folder" item in the VS setup project is not accessible, even when "Install for all users" is used during installation. I could easily hack around this, but would like to understand best practice]

推荐答案

我不确定哪个位置存储XML文件更好.我认为这并不重要.但是,如果您需要在系统中获取特殊的文件夹路径,则可以使用Environment类来实现.下面的代码行获取程序文件的路径:

I am not sure which place is better to store the XML file. I don't think it will matter alot. But if you need to get special folder path in the system you can use Environment class to do so. The following line of code get the path of the Program Files:

string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);

更多推荐

在C#中找到安装程序路径

本文发布于:2023-11-03 07:34:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554582.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:安装程序   路径   中找到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!