Thursday, March 3, 2011

Vista and ProgramData

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

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

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

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

    CString strPath;
    ::SHGetSpecialFolderPath(NULL, strPath.GetBuffer(1024), CSIDL_COMMON_APPDATA, FALSE);
    
  • 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.

    frast : 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.
  • 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?"

  • 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

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

0 comments:

Post a Comment