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

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

string strAssemblyFilePath = Assembly.GetExecutingAssembly().Location;
string strAssemblyDirPath = Path.GetDirectoryName(strAssemblyFilePath);
strPath
= strAssemblyDirPath + "\\Log";
原文地址:https://www.cnblogs.com/xiebin1986/p/1813400.html