Trending Up...

Trending Up...

Get app path (.NET 1.1)




//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;
    }
}
阅读更多
个人分类: C#
上一篇Quotation report(Three layers)
下一篇C# Create Window Service (.NET 1.1)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭