在 Win7 上存储可供多个用户帐户访问和操作的数据文件的好地方是什么?
因此,我一直在开发一个包含多个部分的系统,例如标准用户模式应用程序、Internet Explorer 插件和 Windows 服务。我需要能够从可能在不同用户帐户下运行的所有这些部分访问和/或操作同一组数据文件。我似乎对存储这些数据的最佳位置有点困惑。
我当前正在使用“所有用户”配置文件下的目录。唯一的问题是,当从在本地系统帐户下运行的 Windows 服务调用时,SHFileOperation 似乎无法从该目录中删除文件;我收到文件未找到错误。我意识到从 Vista 开始,SHFileOperation 已被 IFileOperation 取代,我更新了该代码以使用 IFileOperation,它确实在这里工作,但我想知道我是否可能会遇到其他问题。
那么,问题是,在Win7上是否有比“所有用户”配置文件下“更好”的地方来存储这些数据文件呢?
So I've been working on a system that includes multiple parts, such as a standard user-mode application, a plug-in for Internet Explorer, and a Windows Service. I need to be able to access and/or manipulate the same set of data files from all of these parts which may run under different user accounts. And I seem to be a little confused about the best place to store that data.
I am currently using a directory under the "All Users" profile. The only problem with this is that SHFileOperation does not seem to work to delete files from this directory when called from the Windows Service that runs under the Local System account; I get a file not found error. I realize that SHFileOperation is superseded by IFileOperation as of Vista, and I updated that code to use IFileOperation and it does indeed work here, but I'm wondering if I might run into other issues down the road.
So, the question is, is there a "better" place to store these data files on Win7 than under the "All Users" profile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ProgramData 是必经之路。在我的(非常默认的)Windows 7 安装中,它映射到 C:\ProgramData。它不受 UAC 保护,因此没有人需要提升才能访问它。在其中创建一个包含您的应用程序名称的文件夹,然后就可以开始了。 %ProgramData% 将从批处理文件等中访问它,并且您应该能够找到它,但是您找到已知的文件夹 - CSIDL_COMMON_APPDATA 如果您使用本机代码,托管代码中的 System.Environment.SpecialFolders - 如果它不在该枚举中然后代码包中有一个它的代码。
对于某些用户来说,如果他们喜欢在“我的文档”下查看,找到该文件可能会有点困难,但使用 AllUsers 配置文件也可能会遇到这个问题。
ProgramData is the way to go. On my (pretty default) Windows 7 installation it maps to C:\ProgramData. It's not protected by UAC so nobody has to elevate to get to it. Make a folder in there with the name of your app and away you go. %ProgramData% will reach it from batch files etc, and you should be able to find it however you find known folders - CSIDL_COMMON_APPDATA if you're working in native code, System.Environment.SpecialFolders in managed code - if it's not in that enum then there's one in the Code Pack for it.
It can be a little hard for some users to find the file, if they like to look under My Documents, but then using the AllUsers profile might have that problem too.