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

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

string strAssemblyFilePath = Assembly.GetExecutingAssembly().Location;string
 strAssemblyDirPath = Path.GetDirectoryName(strAssemblyFilePath);
strPath = strAssemblyDirPath + "\\Log";

  

posted @ 2011-10-27 12:12  小锋神  阅读(933)  评论(0编辑  收藏  举报