Paul Crowley
Paul Crowley

Reputation: 1714

Where on the filesystem should a Windows service persist its data?

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?

Upvotes: 8

Views: 3034

Answers (3)

Locksfree
Locksfree

Reputation: 2702

If this is a .NET service I think you could use IsolatedStorage

Upvotes: 0

Magnus Johansson
Magnus Johansson

Reputation: 28325

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);

Upvotes: 4

dkackman
dkackman

Reputation: 15559

If you want it to be consistent (i.e. user agnostic) try Application.CommonAppDataPath.

Upvotes: 4

Related Questions