开发者

Where should Windows Services write Application Data?

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 serv开发者_如何学Goice 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜