Reputation: 22275
I'm writing a service using C# that is supposed to run on a Windows platform as the "local system". I can store small amounts of data in the registry, but if I want to store more data in a file, where do I place such file in? And also how to protect that data from a modification by users with lower access rights?
Upvotes: 4
Views: 3520
Reputation: 11
Update to previous answer that may save some troubleshooting time to people using this solution (as I don't have enough reputation to comment):
For Local System Windows service account, Environment.SpecialFolder.LocalApplicationData
may also be resolved to
C:\Windows\SysWOW64\config\systemprofile\AppData\Local
instead of C:\Windows\System32\Config\SystemProfile\AppData\Local
.
Using the already mentioned CommonApplicationData instead of LocalApplicationData does not bring this issue.
Information source: https://www.jamescrowley.net/2014/02/24/appdata-location-when-running-under-system-user-account/
Upvotes: 1
Reputation: 46050
General approach is to use ProtectedData class to encrypt the data, then store them anywhere on the disk where the application can (eg in a subfolder of LocalApplicationData special folder, whose location you can obtain using Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData
call).
Upvotes: 6