Click here to Skip to main content
15,903,854 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Returning a class reference Pin
CPallini24-Apr-07 3:02
mveCPallini24-Apr-07 3:02 
GeneralRe: Returning a class reference Pin
Stephen Hewitt24-Apr-07 3:26
Stephen Hewitt24-Apr-07 3:26 
GeneralRe: Returning a class reference Pin
CPallini24-Apr-07 3:45
mveCPallini24-Apr-07 3:45 
GeneralRe: Returning a class reference Pin
Stephen Hewitt24-Apr-07 4:04
Stephen Hewitt24-Apr-07 4:04 
AnswerRe: Returning a class reference Pin
Stephen Hewitt24-Apr-07 3:34
Stephen Hewitt24-Apr-07 3:34 
AnswerRe: Returning a class reference Pin
Michael Dunn24-Apr-07 8:39
sitebuilderMichael Dunn24-Apr-07 8:39 
GeneralRe: Returning a class reference Pin
TheDelChop24-Apr-07 8:40
TheDelChop24-Apr-07 8:40 
Questionchange permissions of an existing registry key Pin
programvinod24-Apr-07 2:53
programvinod24-Apr-07 2:53 
Hi,

I have a key, for that i need to change the permissions for admins to full control, system to full control and power usres to only have read access and all others should not have access.

i have written this code,RegSetRegisterKey API is executing correctly, but if i open the registry using regedit, and open the dialog box for permissions, it is not checking the check boxes for full control and read access.

How to make these check boxes to check for the respective permissions.


SID_IDENTIFIER_AUTHORITY securityid = SECURITY_NT_AUTHORITY;
PSID pAdministratorsSid = NULL;
PSID pSystemSid = NULL;
PSID pPowerusersSid = NULL;
SECURITY_DESCRIPTOR sd;
PACL pDacl = NULL;
DWORD dwAclSize;
HKEY hKey;
LONG lRetCode;
BOOL bSuccess = FALSE;

lRetCode = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\mykey"),
0,
WRITE_DAC,
&hKey
);

if(lRetCode != ERROR_SUCCESS) {
printf("RegOpenKeyEx error! (rc=%lu)\n", lRetCode);
return RTN_ERROR;
}

if(!AllocateAndInitializeSid(
&securityid,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&pAdministratorsSid
)) goto cleanup;

AllocateAndInitializeSid(
&securityid,
1,
SECURITY_LOCAL_SYSTEM_RID,
0, 0, 0, 0, 0, 0, 0,
&pSystemSid
) ;


AllocateAndInitializeSid(
&securityid,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_POWER_USERS,
0, 0, 0, 0, 0, 0,
&pPowerusersSid
);

dwAclSize = sizeof(ACL) +
3 * ( sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) ) +
GetLengthSid(pSystemSid)
+GetLengthSid(pAdministratorsSid)
+GetLengthSid(pPowerusersSid);




pDacl=(PACL)LocalAlloc(0,dwAclSize);
if(pDacl == NULL) goto cleanup;

if(!InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
goto cleanup;

if(!AddAccessAllowedAce(
pDacl,
ACL_REVISION,
KEY_ALL_ACCESS,
pAdministratorsSid
)) goto cleanup;

AddAccessAllowedAce(
pDacl,
ACL_REVISION,
KEY_READ,
pPowerusersSid
) ;

AddAccessAllowedAce(
pDacl,
ACL_REVISION,
KEY_ALL_ACCESS,
pSystemSid
) ;

if(!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
goto cleanup;

if(!SetSecurityDescriptorDacl(&sd, TRUE, pDacl, TRUE)) {
printf("SetSecurityDescriptorDacl error! (rc=%lu)\n",
GetLastError());
goto cleanup;
}

lRetCode = RegSetKeySecurity(
hKey,
(SECURITY_INFORMATION)DACL_SECURITY_INFORMATION,
&sd
);

if(lRetCode != ERROR_SUCCESS) {
printf("fail\n);
goto cleanup;
}
else printf("Success"); //i am getting success

bSuccess = TRUE; // indicate success

cleanup:

RegCloseKey(hKey);
RegCloseKey(HKEY_LOCAL_MACHINE);

if(pDacl != NULL)
HeapFree(GetProcessHeap(), 0, pDacl);

if(pSystemSid != NULL)
FreeSid(pSystemSid);

if(pAdministratorsSid != NULL)
FreeSid(pAdministratorsSid);
if(pPowerusersSid != NULL)
FreeSid(pPowerusersSid);





QuestionTree in MFC Pin
T.RATHA KRISHNAN24-Apr-07 2:20
T.RATHA KRISHNAN24-Apr-07 2:20 
QuestionRe: Tree in MFC Pin
CPallini24-Apr-07 2:24
mveCPallini24-Apr-07 2:24 
AnswerRe: Tree in MFC Pin
T.RATHA KRISHNAN24-Apr-07 2:30
T.RATHA KRISHNAN24-Apr-07 2:30 
GeneralRe: Tree in MFC Pin
CPallini24-Apr-07 2:34
mveCPallini24-Apr-07 2:34 
AnswerRe: Tree in MFC Pin
prasad_som24-Apr-07 2:41
prasad_som24-Apr-07 2:41 
QuestionFile Issue Pin
Try24-Apr-07 2:10
Try24-Apr-07 2:10 
AnswerRe: File Issue Pin
CPallini24-Apr-07 2:27
mveCPallini24-Apr-07 2:27 
AnswerRe: File Issue Pin
David Crow24-Apr-07 2:49
David Crow24-Apr-07 2:49 
GeneralRe: File Issue Pin
Try24-Apr-07 3:14
Try24-Apr-07 3:14 
GeneralRe: File Issue Pin
David Crow24-Apr-07 3:22
David Crow24-Apr-07 3:22 
GeneralRe: File Issue Pin
Try24-Apr-07 3:27
Try24-Apr-07 3:27 
Questiona star algorithm Pin
s chiddarwar24-Apr-07 0:57
s chiddarwar24-Apr-07 0:57 
QuestionRe: a star algorithm Pin
Maximilien24-Apr-07 2:25
Maximilien24-Apr-07 2:25 
AnswerRe: a star algorithm Pin
s chiddarwar24-Apr-07 5:07
s chiddarwar24-Apr-07 5:07 
AnswerRe: a star algorithm Pin
kakan24-Apr-07 2:37
professionalkakan24-Apr-07 2:37 
GeneralRe: a star algorithm Pin
s chiddarwar24-Apr-07 5:06
s chiddarwar24-Apr-07 5:06 
GeneralRe: a star algorithm Pin
kakan24-Apr-07 19:59
professionalkakan24-Apr-07 19:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.