Question : is there a way to programmatically change folder permissions in windows vista?

either with mfc or .net (c++ or c# preferred)

Here's the scenario - I have an MFC dialog app that I am trying to make vista-compatible.  I need to be able to write to files in the installpath (and subdirs) at all time, so I figure that i need to give the "Everyone" account full access to the folder.  Can I do this with code, or will I need to have the end user change the permissions?

Thanks for any suggestions you can offer!!

Answer : is there a way to programmatically change folder permissions in windows vista?

Use

    LPTSTR FileName = "C:\\Temp\\MyDir";
    LPTSTR TrusteeName = "Everyone";

    DWORD AccessMask = GENREIC_READ | GENERIC_WRITE;
    ACCESS_MODE option = GRANT_ACCESS;
    DWORD InheritFlag = CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE;    
    EXPLICIT_ACCESS explicitaccess;


    PACL ExistingDacl;
    PACL NewAcl = NULL;
    PSECURITY_DESCRIPTOR psd = NULL;

    DWORD dwError;

    dwError = GetNamedSecurityInfo(
                        FileName,
                        SE_FILE_OBJECT,
                        DACL_SECURITY_INFORMATION,
                        NULL,
                        NULL,
                        &ExistingDacl,
                        NULL,
                        &psd
                        );

    BuildExplicitAccessWithName(
            &explicitaccess,
            TrusteeName,
            AccessMask,
            option,
            InheritFlag
            );

    //
    // add specified access to the object
    //

    dwError = SetEntriesInAcl(
            1,
            &explicitaccess,
            ExistingDacl,
            &NewAcl
            );

    //
    // apply new security to file
    //

    dwError = SetNamedSecurityInfo(
                    FileName,
                    SE_FILE_OBJECT, // object type
                    DACL_SECURITY_INFORMATION,
                    NULL,
                    NULL,
                    NewAcl,
                    NULL
                    );

(This is a stripped down version of the MS' AclAPI sample)
Random Solutions  
 
programming4us programming4us