views:

29

answers:

2

Hi,

We have a Windows Service as part of our software, this is used to transfer data to a remote database in the background even when there is no user logged into the system. Currently this data is cached in the Program Files directory, and I don't think this is a good idea because it requires us to reduce the security permissions on our directories in Program Files. I think it should be caching this %LocalAppData% folder, so that we don't have to do this.

What is considered best practise here?

As an extra requirement we tend to run the service as a normal application during development to make debugging easier, and it would be nice if we could switch modes easily without losing any cached data. Although we can live without this if necessary.

Thanks

A: 

I would say that the best place is the user AppData folder for the user that the service is running as. Do you use the default Local Service user or a custom user? I'm not sure which directory the Local Service user's AppData will resolve to, but I think that's the one you want.

the_mandrill
I believe we are running as a custom user.
Andy Lowry
+1  A: 

Yes, you should create your files under %LocalAppData% instead of a system-wide location. You can pass CSIDL_LOCAL_APPDATA to SHGetFolderPath() in order to get the actual name of that folder.

During development, you can configure the service to impersonate the connected user in order to store the files in the same place both in service and normal application mode.

Frédéric Hamidi