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?
The Services file is typically located in %windir%\System32\drivers\etc\services. If the file is missing, check with your system administrator before starting the database server installation process.
Both are real services. Windows Services have existed for over 20 years. They start most often at system startup and run permanently. A Worker Service is also a real process, but is intended as a background service for a front-end application; it starts with the application and stops with the application.
Automatic – services will start at boot time. Automatic (Delayed Start) – services will start just after boot time. Manual – Start a service manually when needed. Disabled – Stop a service from starting, even if needed.
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);
If you want it to be consistent (i.e. user agnostic) try Application.CommonAppDataPath
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With