7

Possible Duplicate:
VS2008 Setup Project: Shared (By All Users) Application Data Files?

Please can someone advice what is the best place (path) to put some application data which should be accessible and editable by all users.

This is considering both Windows XP and Windows Vista and i expect that change in any file of above path does NOT trigger UAC!

Community
  • 1
  • 1
Hemant
  • 19,486
  • 24
  • 91
  • 127

10 Answers10

5

Plain Win API: SHGetFolderPath with CSIDL_COMMON_APPDATA as folder type.

Alex B
  • 82,554
  • 44
  • 203
  • 280
2
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

Should resolve to C:\Documents and Settings\All Users\Application Data\

From there, make subfolders such as MyCompany\MyApp

JC.
  • 11,561
  • 11
  • 41
  • 50
2

VS2008 Setup Project: Shared (By All Users) Application Data Files?

Community
  • 1
  • 1
2

If you're using .NET, Application.CommonAppDataPath should work. Also make sure that virtualization is turned off for your application

DotNET
  • 309
  • 2
  • 7
1

%ALLUSERSPROFILE%\Application Data\App
this is probably the only directory that all users can access without elevated privileges.

tloach
  • 8,009
  • 1
  • 33
  • 44
  • This is quite harcoded, and the "Application Data" folder could be in other language. Any way to internationalize the name of "Application Folder" ? – Romias Apr 25 '09 at 20:09
1

If you're using .NET, Application.CommonAppDataPath should work.

Timothy Carter
  • 15,459
  • 7
  • 44
  • 62
1

If the users are not going to modify the data directly, and it will only be modified by the app, how about IsolatedStorage - http://msdn.microsoft.com/en-us/library/3ak841sy(VS.80).aspx

Paul Nearney
  • 6,965
  • 2
  • 30
  • 37
1

Checkers provides the vital clue to do this in C or C++. So I have voted his answer.

Here are the details he left out:

// 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
ravenspoint
  • 19,093
  • 6
  • 57
  • 103
0

You can also put it in a database.

tuinstoel
  • 7,248
  • 27
  • 27
0

For Vista and higher, MS seems to be pushing for using SHGetKnownFolderPath() instead of SHGetFolderPath(). Choose what folder to ask for from the list of KNOWNFOLDERIDs. Based on the answers here, the equivalent you'd want would probably be FOLDERID_ProgramData. I realize this question is quite old, but I guess for archival purposes..

Doug Kavendek
  • 3,624
  • 4
  • 31
  • 43