王老师:
   您在我今天的另外一个帖子里的回答:“在管理员帐号下RegCreateKeyEx,其中lpSecurityAttributes参数不要给NULL,要给出一个安全描述符,如果要让所有用户访问,可以添加Everyone帐号的访问权限。”   我刚刚测试的时候发现,这种方法好像没有把Guests组里的用户包括进去。其它的标准用户都可以正常修改管理员创建的注册表项,但是Windows自带的默认的Guest用户则无法以写权限打开管理员创建的注册表项。   请问这个有办法解决吗?

解决方案 »

  1.   

    Everyone应该是包含Guest用户的,不会有问题才对。实在不行,你可以把Guests也添加进去。注意,sid和domainname都要分别分配内存,不能共用。
      

  2.   

    试试吧:
    DWORD aclLength = 0x400;
    DWORD sid1Length = 0x400;
    DWORD sid2Length = 0x400;
    DWORD domain1Length = 0x400;
    DWORD domain2Length = 0x400;
    PACL acl = (PACL)new BYTE[aclLength];
    PSID sid1 = (PSID)new BYTE[sid1Length];
    PSID sid2 = (PSID)new BYTE[sid2Length];
    LPTSTR domain1 = new TCHAR[domain1Length];
    LPTSTR domain2 = new TCHAR[domain2Length];
    SID_NAME_USE snu;
    SECURITY_DESCRIPTOR sd;
    SECURITY_ATTRIBUTES sa; InitializeAcl(acl, 0x400, ACL_REVISION);
    LookupAccountName(NULL, _T("Everyone"), sid1, &sid1Length, domain1, &domain1Length, &snu);
    AddAccessAllowedAce(acl, ACL_REVISION, GENERIC_ALL, sid1);
    LookupAccountName(NULL, _T("Guests"), sid2, &sid2Length, domain2, &domain2Length, &snu);
    AddAccessAllowedAce(acl, ACL_REVISION, GENERIC_ALL, sid2);
    InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
    SetSecurityDescriptorDacl(&sd, TRUE, acl, FALSE);
    sa.nLength = sizeof(sa);
    sa.lpSecurityDescriptor = &sd;
    sa.bInheritHandle = FALSE;
    HKEY key;
    // RegCreateKeyEx
    delete domain1;
    delete domain2;
    delete sid1;
    delete sid2;
    delete acl;