放置应用数据的最佳位置?

时间:2008-10-03 13:33:50

标签: windows windows-vista windows-xp filesystems

  

可能重复:
  VS2008 Setup Project: Shared (By All Users) Application Data Files?

请有人建议将所有用户都可以访问和编辑的应用程序数据的最佳位置(路径)放在哪里。

这是考虑Windows XP和Windows Vista,我希望上述路径中任何文件的更改都不会触发UAC!

10 个答案:

答案 0 :(得分:5)

Plain Win API:SHGetFolderPathCSIDL_COMMON_APPDATA作为文件夹类型。

答案 1 :(得分:2)

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

应解析为C:\ Documents and Settings \ All Users \ Application Data \

从那里,创建MyCompany \ MyApp

等子文件夹

答案 2 :(得分:2)

答案 3 :(得分:2)

  

如果您使用的是.NET,Application.CommonAppDataPath应该可以正常工作。   还要确保为您的应用程序关闭虚拟化

答案 4 :(得分:1)

%ALLUSERSPROFILE%\ Application Data \ App
这可能是所有用户无需提升权限即可访问的唯一目录。

答案 5 :(得分:1)

如果您使用的是.NET,Application.CommonAppDataPath应该可以正常工作。

答案 6 :(得分:1)

如果用户不打算直接修改数据,并且只会被应用修改,那么IsolatedStorage如何?http://msdn.microsoft.com/en-us/library/3ak841sy(VS.80).aspx

答案 7 :(得分:1)

Checkers提供了在C或C ++中执行此操作的重要线索。所以我投了他的答案。

以下是他遗漏的细节:

// assumes
// company is a pointer to a character sting containing company name
// appname is a pointer to a character string containing application name
// fname   is a pointer to a character string cintaining name of file to be created

#include <shlobj.h>   // for SHGetFolderPath
#include <direct.h>   // for _mkdir

char path[MAX_PATH];
SHGetFolderPath(NULL,CSIDL_COMMON_APPDATA,NULL,NULL,path);
strcat(path,"/");
strcat(path,company);
_mkdir(path);
strcat(path,"/");
strcat(path,appname);
_mkdir(path);
strcat(path,"/");
strcat(path,fname);

// path is now a character string which can passed to fopen

答案 8 :(得分:0)

您也可以将其放入数据库中。

答案 9 :(得分:0)

对于Vista及更高版本,MS似乎正在推动使用SHGetKnownFolderPath()而不是SHGetFolderPath()。从list of KNOWNFOLDERIDs中选择要求的文件夹。根据这里的答案,你想要的等价物可能是FOLDERID_ProgramData。我意识到这个问题已经很老了,但我猜是出于档案目的......

相关问题