Windows service - get current directory

后端 未结 4 431
庸人自扰
庸人自扰 2020-12-24 10:42

I have a Windows service that should look for a configuration file in its current directory.

So I use directory.getcurrentdirectiry() but instead of the

4条回答
  •  無奈伤痛
    2020-12-24 10:48

    You can set the current directory to the directory that your service is running from by including this line in your code:

    System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
    

    The important part of this is:

    System.AppDomain.CurrentDomain.BaseDirectory
    

    That returns the path to the directory your service is running from.

提交回复
热议问题