C# Directory.GetCurrentDirectory() in program run as service

When an app is run as service (or from Task Scheduler), the Directory.GetCurrentDirectory() method will return ‘C:\Windows\System32‘ (instead of ‘D\AppDirectory‘)
Helpful snippet used before running the method:

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

Leave a Reply

Your email address will not be published. Required fields are marked *