views:

1637

answers:

6

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?

Many thanks in advance.

Best regards, frast

A: 

Its an environment variable, accessible same as any others: %ProgramData%

mattlant
Thank you but this is not the answer to my question.
frast
Good! Now make sure you hit the downvote button. Its there for exactly this reason! Its your duty to wee dout unhelpful answrers :)
mattlant
I do not have the required 100 reputation.
frast
now you can delete it and get a peer pressure badge!
amdfan
+6  A: 

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.

Franci Penov
I believe that's actually %ALLUSERSPROFILE%, with an S
Factor Mystic
Err, yes, that is correct, I missed an S. :-)
Franci Penov
A: 

You can use:

CString strPath;
::SHGetSpecialFolderPath(NULL, strPath.GetBuffer(1024), CSIDL_COMMON_APPDATA, FALSE);
dennisV
+2  A: 

See Raymond Chen's article on this specific question: http://blogs.msdn.com/oldnewthing/archive/2004/11/22/267890.aspx

In short you're asking for a security hole.

VVS
The 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
+3  A: 

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?"

amdfan
+4  A: 

Actually SHGetFolderPath is deprecated: http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx

SHGetKnownFolderPath should be used instead: http://msdn.microsoft.com/en-us/library/bb762188(VS.85).aspx

Enrico Detoma
If I would use SHGetKnownFolderPath my software would only run under Windows Vista. SHGetFolderPath works since Windows 2000 and on Vista too.
frast