Get app path (.NET 1.1)
2007-09-21 16:25
375 查看
//general
AppDomain.CurrentDomain.BaseDirectory
Environment.CurrentDirectory
//Get Application Full Path(EXE, DLL, Service..)
System.Reflection.Assembly.GetExecutingAssembly().Location
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location)
// Only for exe
Application.ExecutablePath
// Only for Window Service
public class MyService : System.ServiceProcess.ServiceBase
{
this.ServiceName = "MyService";
....
string ServicePath()
{
string ret = null;
ManagementObjectSearcher Searcher = new
ManagementObjectSearcher("SELECT PathName from Win32_Service " +
"WHERE DisplayName =" + "/"" + this.ServiceName + "/"");
foreach(ManagementObject service in Searcher.Get())
{
ret = service["PathName"].ToString();
}
return ret;
}
}
AppDomain.CurrentDomain.BaseDirectory
Environment.CurrentDirectory
//Get Application Full Path(EXE, DLL, Service..)
System.Reflection.Assembly.GetExecutingAssembly().Location
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location)
// Only for exe
Application.ExecutablePath
// Only for Window Service
public class MyService : System.ServiceProcess.ServiceBase
{
this.ServiceName = "MyService";
....
string ServicePath()
{
string ret = null;
ManagementObjectSearcher Searcher = new
ManagementObjectSearcher("SELECT PathName from Win32_Service " +
"WHERE DisplayName =" + "/"" + this.ServiceName + "/"");
foreach(ManagementObject service in Searcher.Get())
{
ret = service["PathName"].ToString();
}
return ret;
}
}
相关文章推荐
- asp.net get App_Data 目录几种方法 path
- Caused by: java.lang.ClassNotFoundException: Didn't find class "net.oschina.app.AppContext" on path:
- MFC学习20160718(GetModuleFileName&&GetAppDataPath)
- .Net AppDomain.CurrentDomain.AppendPrivatePath(@"Libs");
- 解决ASP.NET错误 Failed to map the path '/App_GlobalResources/'
- 运行DotNetNuke 6 源码出现string strMessage = DataProvider.Instance().GetProviderPath();异常的解决办法
- How to get Intellisense for Web.config and App.config in Visual Studio .NET?(转载)
- Get .net framwork path
- Xcode报错:"Geo::GetiOSAppDocumentsDir()",Geo::PathUtils::GetSandboxDataPath()
- WebService报错: No such operation: (HTTP GET PATH_INFO: /flexcc/flexccService/flexccApp)
- Servlet.service() for servlet [springMVC] in context with path [] threw exception [Could not get Req
- [Exception] – Could not load file or assembly App_Web_*** ASP.NET
- ASP.net 1.1 中相对路径转换为绝对路径
- 文件路径的获取《file的getPath getAbsolutePath和getCanonicalPath的不同》
- HOW TO:使用 GetOleDbSchemaTable 和 Visual C# .NET 检索架构信息
- asp.net获取传值get和post请求
- File的getPath getAbsolutePath和getCanonicalPath的不同
- ${pageContext.request.contextPath} 与 <%=request.getContextPath()%>
- .net get set用法小结第1/3页
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别