I'm writing a Windows service which needs to persist some data across reboots/restarts of the service. Currently I'm writing the files in a directory returned by Application.UserAppDataPath
, but that doesn't seem to be giving me a consistent answer. How should I determine the right place to write the data?
views:
199answers:
3
+3
A:
If you want it to be consistent (i.e. user agnostic) try Application.CommonAppDataPath
.
dkackman
2009-09-23 11:34:30
I agree. If the service is running as LocalSystem then it makes sense to store data in the user-independent data path.
Christian Hayter
2009-09-23 11:38:51
+1
A:
It depends if your service is running with the system account or with a specific user account.
System account. Store the files in the CommonApplicationData folder:
string pathForSystem = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
User account. Store the files in the ApplicationData folder:
string pathForUser = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Magnus Johansson
2009-09-23 11:38:52