Click here to Skip to main content
15,924,317 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionC++ text button save Pin
Anka_Ame26-Apr-07 3:59
Anka_Ame26-Apr-07 3:59 
AnswerRe: C++ text button save Pin
Christian Graus26-Apr-07 12:11
protectorChristian Graus26-Apr-07 12:11 
Questioncapturing time via rs232 Pin
braleping25-Apr-07 17:07
braleping25-Apr-07 17:07 
AnswerRe: capturing time via rs232 Pin
Christian Graus26-Apr-07 12:19
protectorChristian Graus26-Apr-07 12:19 
QuestionWindows Forms Pin
Anka_Ame25-Apr-07 6:06
Anka_Ame25-Apr-07 6:06 
AnswerRe: Windows Forms Pin
sarah_malik25-Apr-07 14:38
sarah_malik25-Apr-07 14:38 
QuestionDefinition of a Class in C++ (.NET Platform) Pin
Debun24-Apr-07 15:58
Debun24-Apr-07 15:58 
Questionchange permissions of an existing registry key Pin
programvinod23-Apr-07 22:37
programvinod23-Apr-07 22:37 
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);







AnswerRe: change permissions of an existing registry key Pin
Christian Graus24-Apr-07 0:37
protectorChristian Graus24-Apr-07 0:37 
QuestionJava/C++.......Help me.!!! Pin
Skydeegay23-Apr-07 15:36
Skydeegay23-Apr-07 15:36 
AnswerRe: Java/C++.......Help me.!!! Pin
Christian Graus23-Apr-07 15:56
protectorChristian Graus23-Apr-07 15:56 
GeneralRe: Java/C++.......Help me.!!! Pin
Skydeegay24-Apr-07 0:09
Skydeegay24-Apr-07 0:09 
GeneralRe: Java/C++.......Help me.!!! Pin
George L. Jackson24-Apr-07 0:13
George L. Jackson24-Apr-07 0:13 
GeneralRe: Java/C++.......Help me.!!! Pin
Skydeegay24-Apr-07 1:30
Skydeegay24-Apr-07 1:30 
GeneralRe: Java/C++.......Help me.!!! Pin
George L. Jackson24-Apr-07 1:49
George L. Jackson24-Apr-07 1:49 
GeneralRe: Java/C++.......Help me.!!! Pin
Christian Graus24-Apr-07 0:32
protectorChristian Graus24-Apr-07 0:32 
GeneralRe: Java/C++.......Help me.!!! Pin
Skydeegay24-Apr-07 1:24
Skydeegay24-Apr-07 1:24 
QuestionC++/CLI dll trying to access managed code which is inside an unmanaged static library Pin
Bipin12323-Apr-07 13:23
Bipin12323-Apr-07 13:23 
GeneralRe: C++/CLI dll trying to access managed code which is inside an unmanaged static library Pin
George L. Jackson23-Apr-07 13:54
George L. Jackson23-Apr-07 13:54 
Questionhow can I make dll in c++ for c# Pin
lavy288323-Apr-07 5:56
lavy288323-Apr-07 5:56 
AnswerRe: how can I make dll in c++ for c# Pin
led mike23-Apr-07 6:08
led mike23-Apr-07 6:08 
GeneralRe: how can I make dll in c++ for c# Pin
lavy288323-Apr-07 7:07
lavy288323-Apr-07 7:07 
GeneralRe: how can I make dll in c++ for c# Pin
Mark Salsbery23-Apr-07 7:14
Mark Salsbery23-Apr-07 7:14 
GeneralRe: how can I make dll in c++ for c# Pin
lavy288323-Apr-07 7:53
lavy288323-Apr-07 7:53 
GeneralRe: how can I make dll in c++ for c# Pin
Mark Salsbery23-Apr-07 7:59
Mark Salsbery23-Apr-07 7: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.