关闭

Get app path (.NET 1.1)

657人阅读 评论(0) 收藏 举报



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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:299966次
    • 积分:5378
    • 等级:
    • 排名:第4975名
    • 原创:238篇
    • 转载:27篇
    • 译文:0篇
    • 评论:8条
    文章分类
    最新评论