Consistent ApplicationData path between WinForms Apps and Windows Service contexts in C#
问题 I use the following code to build a desired path for an XML file: System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); When executed from a Windows Forms application, it returns: C:\Users\MyUsername\AppData\Roaming\...\Database.xml When executed from within a Windows Service, it returns: C:\Windows\system32\config\systemprofile\AppData\Roaming\...\Database.xml I am now resorting to having a custom installer action persist the path in a registry key since the