您的位置:首页 > 移动开发

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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: