您的位置:首页 > 其它

.Net Windows服务程序中获取安装程序所在目录

2010-08-31 10:22 330 查看
在Windows服务程序中,有时希望获得安装程序所在的目录对齐对其进行操作,如生成Log日志文件等,若用语句System.Environment.CurrentDirectory则返回的路径为C:\WINDOWS\system32不能正确指向安装程序所在路径,改用如下代码即可实现。

string strAssemblyFilePath = Assembly.GetExecutingAssembly().Location;
string strAssemblyDirPath = Path.GetDirectoryName(strAssemblyFilePath);
strPath = strAssemblyDirPath + "\\Log";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: