Search code examples
c#windows-services

Windows Service installation - current directory


this question is related to my previous one . I've written a service in C# and I need to make it's name dynamic and load the name from configuration file. The problem is that current directory while the service installer is invoked is the net framework 4 directory instead of the one that my assembly sits in.

Using the line (which helps with the same problem, but while the service is already running) System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

sets the directory to

C:\Windows\Microsoft.NET\Framework\v4.0.30319

which was also the initial value.

How to get the right path?


Solution

  • try this one:

    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);