2008-10-03 116 views

回答

2
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) 

應解析爲C:\ Documents和Settings \所有用戶\應用數據\

從那裏,讓子如MyCompany的\ MyApp的

1

%ALLUSERSPROFILE%\應用程序數據\應用程序
這可能是所有用戶無需提升權限即可訪問的唯一目錄。

+0

這是相當harcoded,並且「應用程序數據」文件夾可以用其他語言。任何方式來國際化「應用程序文件夾」的名稱? – Romias 2009-04-25 20:09:32

1

如果您使用.NET,Application.CommonAppDataPath應該可以工作。

+0

是不是winforms-only? – 2010-05-25 20:56:55

5

Plain Win API:SHGetFolderPathCSIDL_COMMON_APPDATA作爲文件夾類型。

1

跳棋提供了重要線索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 
2

如果您使用.NET,Application.CommonAppDataPath應該工作。 還要確保爲您的應用程序關閉虛擬化

0

您也可以將其放入數據庫中。

0

對於Vista及更高版本,MS似乎在推動使用SHGetKnownFolderPath()而不是SHGetFolderPath()。從list of KNOWNFOLDERIDs中選擇要求的文件夾。基於這裏的答案,你想要的等價物可能是FOLDERID_ProgramData。我意識到這個問題是相當古老的,但我想爲檔案的目的..

相關問題