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

mac2022-06-30  90

    在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/archive/2010/08/31/1813400.html

最新回复(0)