What is the right place to store program data files which are the same for every user but have to be writeable for the program? What would be the equivalent location on MS Windows XP? I have read that C:\ProgramData is not writeable after installation by normal users. Is that true? How can I retrieve that directory programmatically using the Platform SDK?
5 Answers
SHGetFolderPath()
with CSIDL of CSIDL_COMMON_APPDATA
.
Read more at http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx
If you need the path in a batch file, you can also use the %ALLUSERSPROFILE%
environment variable.

- 17,769
- 16
- 66
- 164

- 74,861
- 18
- 132
- 169
-
1I believe that's actually %ALLUSERSPROFILE%, with an S – Factor Mystic May 03 '09 at 21:53
There is a great summary of the different options here: http://blogs.msdn.com/cjacks/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?"

- 14,014
- 8
- 55
- 80
Actually SHGetFolderPath
is deprecated.
SHGetKnownFolderPath
should be used instead.

- 236,525
- 50
- 385
- 514

- 3,159
- 3
- 37
- 53
-
If I would use SHGetKnownFolderPath my software would only run under Windows Vista. SHGetFolderPath works since Windows 2000 and on Vista too. – frast Feb 23 '09 at 14:35
-
@frast, yes, but you can check for SHGetKnowFolderPath availability and use it if exits. (With LoadProc or whatever it's called...) Then your app will be future proof and work on Windows versions where SHGetFolderPath is dropped, as well as on Windows 2000. – Prof. Falken Nov 05 '10 at 14:46
-
1@Amigable I would do this, but I wait until I see a Windows version that does not support SHGetFolderPath. – frast Nov 05 '10 at 14:49
-
@frast, quite possibly never then, since Microsoft often keep old interfaces a _long_ time. :) – Prof. Falken Nov 05 '10 at 14:51
-
@Amigable Right. Stable interfaces are a good thing and I am to lazy to use all the new merits of Windows Vista :) – frast Nov 05 '10 at 14:55
-
@frast, I will confess, I have a Windows NT 4 in a virtual machine to check if any C program I create will work there too. :-) – Prof. Falken Nov 05 '10 at 15:00
-
-
@frast I have it just for fun. I don't have any real applications. I also get a kick out of running old stuff. The coolest is when a program works well on NT4 --> Windows 7. Like Opera does. – Prof. Falken Nov 05 '10 at 15:07
You can use:
CString strPath;
::SHGetSpecialFolderPath(NULL, strPath.GetBuffer(1024), CSIDL_COMMON_APPDATA, FALSE);

- 1,119
- 3
- 19
- 34
See Raymond Chen's article on this specific question.
In short you're asking for a security hole.
-
3The application will not be used by administrators and everybody who can login to the computer is trusted in companies we are dealing with. So it is not a security issue to have shared data between users. On Vista one can share pictures and movies in a public folder. Progams should have this too. – frast Sep 25 '08 at 11:47