可能重複:
VS2008 Setup Project: Shared (By All Users) Application Data Files?放置應用程序數據的最佳位置?
請某人建議什麼是最好的地方(路徑)把它應該是由所有用戶訪問和編輯的一些應用程序數據。
這是考慮到Windows XP和Windows Vista,我期望在上述路徑的任何文件中的更改不會觸發UAC!
可能重複:
VS2008 Setup Project: Shared (By All Users) Application Data Files?放置應用程序數據的最佳位置?
請某人建議什麼是最好的地方(路徑)把它應該是由所有用戶訪問和編輯的一些應用程序數據。
這是考慮到Windows XP和Windows Vista,我期望在上述路徑的任何文件中的更改不會觸發UAC!
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
應解析爲C:\ Documents和Settings \所有用戶\應用數據\
從那裏,讓子如MyCompany的\ MyApp的
%ALLUSERSPROFILE%\應用程序數據\應用程序
這可能是所有用戶無需提升權限即可訪問的唯一目錄。
如果您使用.NET,Application.CommonAppDataPath應該可以工作。
是不是winforms-only? – 2010-05-25 20:56:55
Plain Win API:SHGetFolderPath與CSIDL_COMMON_APPDATA
作爲文件夾類型。
如果用戶不打算直接修改數據,它只能由應用程序進行修改,怎麼樣IsolatedStorage - http://msdn.microsoft.com/en-us/library/3ak841sy(VS.80).aspx
跳棋提供了重要線索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
如果您使用.NET,Application.CommonAppDataPath應該工作。 還要確保爲您的應用程序關閉虛擬化
您也可以將其放入數據庫中。
對於Vista及更高版本,MS似乎在推動使用SHGetKnownFolderPath()而不是SHGetFolderPath()。從list of KNOWNFOLDERIDs中選擇要求的文件夾。基於這裏的答案,你想要的等價物可能是FOLDERID_ProgramData
。我意識到這個問題是相當古老的,但我想爲檔案的目的..
這是相當harcoded,並且「應用程序數據」文件夾可以用其他語言。任何方式來國際化「應用程序文件夾」的名稱? – Romias 2009-04-25 20:09:32