Vista和ProgramData
时间:2020-03-06 14:42:20 来源:igfitidea点击:
在哪里存储每个用户都相同但必须对程序可写的程序数据文件在什么地方正确? MS Windows XP上的等效位置是什么?我已经读过,普通用户安装后C:\ ProgramData是不可写的。真的吗?如何使用Platform SDK以编程方式检索该目录?
解决方案
带有CSIDL_COMMON_APPDATA的CSIDL的SHGetFolderPath()。
在http://msdn.microsoft.com/zh-cn/library/bb762181(VS.85).aspx中了解更多信息
如果我们需要批处理文件中的路径,则还可以使用%ALLUSERSPROFILE%环境变量。
我们可以使用:
CString strPath; ::SHGetSpecialFolderPath(NULL, strPath.GetBuffer(1024), CSIDL_COMMON_APPDATA, FALSE);
有关此特定问题,请参阅Raymond Chen的文章。
简而言之,我们是在寻求安全漏洞。
这里有不同选项的摘要:http://blogs.msdn.com/cHymans/archive/2008/02/05/where-should-i-write-program-data-instead-of-program-files .aspx
Where Should I Write Program Data Instead of Program Files? A common application code update is this: "my application used to write files to program files. It felt like as good a place to put it as any other. It had my application's name on it already, and because my users were admins, it worked fine. But now I see that this may not be as great a place to stick things as I once thought, because with UAC even Administrators run with standard user-like privileges most of the time. So, where should I put my files instead?"
实际上,不建议使用" SHGetFolderPath"。
应该使用SHGetKnownFolderPath
。