Vista and ProgramData
Asked Answered
F

5

15

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?

Fitts answered 25/9, 2008 at 6:0 Comment(0)
B
8

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.

Bloodletting answered 25/9, 2008 at 6:9 Comment(1)
I believe that's actually %ALLUSERSPROFILE%, with an SHierarchy
S
7

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

Scute answered 23/11, 2008 at 23:34 Comment(0)
G
4

Actually SHGetFolderPath is deprecated.

SHGetKnownFolderPath should be used instead.

Gettogether answered 12/2, 2009 at 0:17 Comment(8)
If I would use SHGetKnownFolderPath my software would only run under Windows Vista. SHGetFolderPath works since Windows 2000 and on Vista too.Fitts
@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.Boren
@Amigable I would do this, but I wait until I see a Windows version that does not support SHGetFolderPath.Fitts
@frast, quite possibly never then, since Microsoft often keep old interfaces a long time. :)Boren
@Amigable Right. Stable interfaces are a good thing and I am to lazy to use all the new merits of Windows Vista :)Fitts
@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. :-)Boren
@Amigable Lucky me. We only support Windows 2000 upwards.Fitts
@Fitts 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.Boren
T
1

You can use:

CString strPath;
::SHGetSpecialFolderPath(NULL, strPath.GetBuffer(1024), CSIDL_COMMON_APPDATA, FALSE);
Tithable answered 25/9, 2008 at 6:10 Comment(0)
T
1

See Raymond Chen's article on this specific question.

In short you're asking for a security hole.

Tinct answered 25/9, 2008 at 6:13 Comment(1)
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.Fitts

© 2022 - 2024 — McMap. All rights reserved.