Getting full path for Windows Service

后端 未结 7 1085
感情败类
感情败类 2021-01-31 01:22

How can I find out the folder where the windows service .exe file is installed dynamically?

Path.GetFullPath(relativePath);

returns a path base

7条回答
  •  时光说笑
    2021-01-31 02:15

    This should give you the path that the executable resides in:

    Environment.CurrentDirectory;
    

    If not, you could try:

    Directory.GetParent(Assembly.GetEntryAssembly().Location).FullName
    

    A more hacky, but functional way:

    Path.GetFullPath("a").TrimEnd('a')
    

    :)

提交回复
热议问题