The backstory: My Visual-Studio 2010 installer package for my Windows MFC C++ application creates a data folder C:\MyDataFolder. Because this is created during the install, the owner of the folder is NT AUTHORITY\SYSTEM
. I would like all (non-admin) users of my application to have Full access to this folder, so I have added some code to give all Authenticated Users Full permissions (SetEntriesInAcl, SetNamedSecurityInfo
, etc.). This works fine when run as an Administrator.
To make this super easy for users, I would like to allow them to install as Admin, then later run the program as a limited user which would attempt to set these permissions, and then prompt them to elevate to Admin if necessary. (This would also cover existing installs that don't yet have these permissions.) I have successfully done this as well (CredUIPromptForWindowsCredentials, CredUnPackAuthenticationBuffer, CredUIParseUserName, LogonUser, ImpersonateLoggedOnUser
). This gives me an elevated token. I have tried it with and without the final call to ImpersonateLoggedOnUser
.
The problem: Retrying the call to SetNamedSecurityInfo
still fails with Access Denied. I have also tried using AdjustTokenPrivileges
to give my elevated token the SE_TAKE_OWNERSHIP_NAME
privilege but this fails with "Not all privileges or groups referenced are assigned to the caller"
I believe I need to take ownership of this folder since it is owned by SYSTEM, but am not sure how to give my elevated token the SE_TAKE_OWNERSHIP_NAME privilege if it doesn't already have it.
I'm very new to all of this so it's very possible I am missing something very basic. I've also had the thought that I should just make a small app that runs during the install and does this, but now that I've come this far I'm being stubborn and want to get the elevation part working. Thanks for any help!