本文发表在 rolia.net 枫下论坛我想把注册表个键原来的Everyone 权限是只读更改为full control,
以下是代码
#define REG1 "SYSTEM\\CurrentControlSet\\Enum\\Root\\IRCOMM2K\\0000\\"
main()
{
SID_IDENTIFIER_AUTHORITY arg1 = {0,0,0,0,0,1};
SECURITY_DESCRIPTOR pSD;
PSID everyone;
PACL pacl;
HKEY hKEY;
DWORD aclSize;
long ret;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG1 , 0, KEY_READ, &hKEY));
ret = AllocateAndInitializeSid(&arg1,1,SECURITY_WORLD_RID,0, 0, 0, 0, 0, 0, 0, &everyone);
aclSize = 2 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + GetLengthSid(everyone));
pacl = (PACL)LocalAlloc(GPTR, aclSize);
ret = InitializeAcl(pacl, aclSize, ACL_REVISION);
ret = AddAccessAllowedAce(pacl, ACL_REVISION, KEY_WRITE,everyone);
ret = InitializeSecurityDescriptor(&pSD, SECURITY_DESCRIPTOR_REVISION);
ret = SetSecurityDescriptorDacl(&pSD, TRUE, pacl, FALSE);
ret = RegSetKeySecurity(hKEY, DACL_SECURITY_INFORMATION, &pSD);
LocalFree(pacl);
}
上边的代码在执行RegSetKeySecurity 函数后,返回个错误代码5(ERROR_ACCESS_DENIED).
另外上边的代码是参考DELPHI , 链接如下:http://groups.google.ca/group/borland.public.delphi.winapi/browse_thread/thread/604db01fe2af765d/a55c0bcae944f16a?lnk=st&q=RegSetKeySecurity+C%2B%2B&rnum=11&hl=en#a55c0bcae944f16a更多精彩文章及讨论,请光临枫下论坛 rolia.net
以下是代码
#define REG1 "SYSTEM\\CurrentControlSet\\Enum\\Root\\IRCOMM2K\\0000\\"
main()
{
SID_IDENTIFIER_AUTHORITY arg1 = {0,0,0,0,0,1};
SECURITY_DESCRIPTOR pSD;
PSID everyone;
PACL pacl;
HKEY hKEY;
DWORD aclSize;
long ret;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG1 , 0, KEY_READ, &hKEY));
ret = AllocateAndInitializeSid(&arg1,1,SECURITY_WORLD_RID,0, 0, 0, 0, 0, 0, 0, &everyone);
aclSize = 2 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + GetLengthSid(everyone));
pacl = (PACL)LocalAlloc(GPTR, aclSize);
ret = InitializeAcl(pacl, aclSize, ACL_REVISION);
ret = AddAccessAllowedAce(pacl, ACL_REVISION, KEY_WRITE,everyone);
ret = InitializeSecurityDescriptor(&pSD, SECURITY_DESCRIPTOR_REVISION);
ret = SetSecurityDescriptorDacl(&pSD, TRUE, pacl, FALSE);
ret = RegSetKeySecurity(hKEY, DACL_SECURITY_INFORMATION, &pSD);
LocalFree(pacl);
}
上边的代码在执行RegSetKeySecurity 函数后,返回个错误代码5(ERROR_ACCESS_DENIED).
另外上边的代码是参考DELPHI , 链接如下:http://groups.google.ca/group/borland.public.delphi.winapi/browse_thread/thread/604db01fe2af765d/a55c0bcae944f16a?lnk=st&q=RegSetKeySecurity+C%2B%2B&rnum=11&hl=en#a55c0bcae944f16a更多精彩文章及讨论,请光临枫下论坛 rolia.net