C++ – Changing vista file permissions programmatically

file-permissionsmfcvisual c++windows-vista

I want to add some files to C:\windows\XXX (windows protected folder, in Vista), under the "TrustedInstaller" for my application. I do not want to replace any file so no issues on Windows Resource(formerly file) protection.
I have the code to change "ownership" to the current logged in admin, however, I'm don't have any clue how to set its file permissions programmatically. I'm using VC++/MFC for development.

Thanks

Best Answer

I not 100% sure what you actually want (as do you want it to look like TrustedInstaller installed the files?) but look at this example of using SetNamedSecurityInfo. You generally need to constuct a Discretionary Access Control List (DACL) for your file, however you can "borrow" one off another file with the permissions you want to clone using GetNamedSecurityInfo as building a DACL from scratch is considerably more annoying.