The smallest access code consists of 3 API calls. It provides full access to this hkey all authenticated users and administrators.
This snippet does not contain proper error handling and reporting. Do not copy / paste it into production code.
PSECURITY_DESCRIPTOR sd = nullptr; ULONG sd_size = 0; TCHAR* rights = TEXT( "D:" ) // Discretionary ACL TEXT( "(A;OICI;GA;;;AU)" ) // Allow full control to all authenticated users TEXT( "(A;OICI;GA;;;BA)" ); // Allow full control to administrators ConvertStringSecurityDescriptorToSecurityDescriptor( rights, SDDL_REVISION_1, &sd, &sd_size ); RegSetKeySecurity( hkey, DACL_SECURITY_INFORMATION, sd ); LocalFree( sd );
Determining whether "users" have write permissions to a key can be more difficult than expected. As a result, I wrote a test value to the registry and checked the result of this entry.
source share