//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;
}
}