Windows service - get current directory

c#, windows-services, working-directory

Solution

Don't use `Directory.GetCurrentDirectory()`. I had the same exact problem with C:\Windows\System32 being returned. Use this instead:

`Path.GetDirectoryName(Application.ExecutablePath);`

Problem

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 service directory I get back ``` c:\windows\system32 ``` Any idea why and how should I get the service directory?

Original source