|
#include "secdesc.h"
int main( int argc)
{
// Initialize 2 EXPLICIT_ACCESS structures: 1 for Everyone,
// 1 for Administrators. Assign KEY_READ privileges to Everyone
// and KEY_ALL_ACCESS priviliges to Administrators.
EXPLICIT_ACCESS ea[2];
ea[0] = CExplicitAccess(KEY_READ, SET_ACCESS, NO_INHERITANCE,
CTrustee(TRUSTEE_IS_WELL_KNOWN_GROUP,
CSid(CSid::WST_EVERYONE)));
ea[1] = CExplicitAccess(KEY_ALL_ACCESS, SET_ACCESS, NO_INHERITANCE,
CTrustee(TRUSTEE_IS_GROUP,
CSid(CSid::WST_LOCALADMINS)));
// Create a new ACL and set the EA entries in it
CAcl acl;
if(acl.SetEntriesInAcl(2, ea) == ERROR_SUCCESS)
{
// Initialize a security descriptor and add our ACL to it
CSecurityDescriptor sd;
if(sd.SetSecurityDescriptorDacl(
TRUE, // fDaclPresent flag
acl,
FALSE)) // not a default DACL
{
// Initialize a security attributes structure.
CSecurityAttributes sa(sd, FALSE);
// Use the security attributes to set the security descriptor
// when you create a key.
DWORD dwDisposition;
HKEY hKey;
RegCreateKeyEx(HKEY_CURRENT_USER, "mykey1", 0, "", 0,
KEY_READ | KEY_WRITE, sa, &hKey, &dwDisposition);
}
}
return GetLastError();
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.