Sunday, February 13, 2011

Changing folder security permisions via Win32 API

My C++ application stores some common user data in %CSIDL_COMMON_APPDATA%\Company\Product. I want to make sure the Users group has write permisions to this folder which on Vista it does not. How would do I do this?

  • Figured it out myself using ATL...

    CDacl oDacl;
    AtlGetDacl(strFolder, SE_FILE_OBJECT, &oDacl);
    oDacl.RemoveAces(Sids::Users()); // Remove existing "Users" access
    oDacl.AddAllowedAce(Sids::Users(), FILE_ALL_ACCESS, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE);
    AtlSetDacl(strFolder, SE_FILE_OBJECT, oDacl);
    

    Of course my real code contains error checking.

    Charles : Too bad I can't mark my own answer as "accepted"
    From Charles

0 comments:

Post a Comment