各种应用程序中获取文件路径的方法
GPS平台、网站建设、软件开发、系统运维,找森大网络科技! http://cnsendnet.taobao.com 来自森大科技官方博客 http://www.cnsendblog.com/index.php/?p=466 用这种方法,web、控制台应用程序、Windows服务都适用 控制台应用程序:Environment.CurrentDirectory、Directory.GetCurrentDirectory() windows服务:Environment.CurrentDirectory windows服务安装成功后: System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName /// /// 获取服务应用程序的安装路径(或者当前安装目录)/// /// /// public static string GetWindowsServiceInstallPath(string ServiceName) { string key = @"SYSTEM\CurrentControlSet\Services\" + ServiceName; string path = Registry.LocalMachine.OpenSubKey(key).GetValue("ImagePath").ToString();