Windows 服务应该在哪里写入应用程序数据? [英] Where should Windows Services write Application Data?

查看:39
本文介绍了Windows 服务应该在哪里写入应用程序数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的软件中有一个 Windows 服务,即使没有用户登录系统,它也可以在后台将数据传输到远程数据库.目前,这些数据缓存在 Program Files 目录中,我认为这不是一个好主意,因为它要求我们降低 Program Files 中目录的安全权限.我认为它应该缓存这个 %LocalAppData% 文件夹,这样我们就不必这样做了.

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.

谢谢

推荐答案

是的,您应该在 %LocalAppData% 而不是系统范围的位置下创建文件.您可以将 CSIDL_LOCAL_APPDATA 传递给 SHGetFolderPath() 以获取该文件夹的实际名称.

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.

这篇关于Windows 服务应该在哪里写入应用程序数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆