To operate a registry key with permission restrictions under Win2K

Source: Internet
Author: User
Tags goto inheritance

In the 2k system operation registry, found that some of the health must have permission problems;

Look at you big stickers, unfortunately not a suitable result;

Some people say: You can improve the user's rights, but in fact it seems to be not very useful;

After a hard, hard, hard struggle; Finally found some good dynamic on MSDN;

I don't want to be alone, (eh, I don't like someone, good things hide where they forget)

Sort out some useful things for some people: Hey, the code is as follows:

Serious suggestion: Everyone put the good things into the bar!!!!!!

Welcome Letter Discussion: lanren_me@etang.com

Start reconfiguring permissions to use the registry------------------------------------------------
LPTSTR Lpobjectname;
Se_object_type ObjectType; #include <aclapi.h>
Pacl Olddacl,newdacl;
Psecurity_descriptor SD;
Explicit_access EA;
Lpobjectname = "Machine\\system\\controlset001\\enum\\root";
ObjectType =se_registry_key;
To establish an empty ACL;
if (setentriesinacl (0, NULL, NULL, &AMP;OLDDACL)!=error_success)
Return
if (setentriesinacl (0, NULL, NULL, &AMP;NEWDACL)!=error_success)
Return
Get the existing ACL list to Olddacl
if (GetNamedSecurityInfo (Lpobjectname, ObjectType,
Dacl_security_information,
NULL, NULL,
&olddacl,
NULL, &AMP;SD)!= error_success)
Application->messagebox ("The specified key does not exist!") "," hint ", MB_OK);
Set user name ' Everyone ' has all rights to the specified key to the structure EA
ZeroMemory (&ea, sizeof (explicit_access));
Buildexplicitaccesswithname (&ea,
"Everyone",//Name of Trustee
Generic_all,//type of Access
Set_access,//ACCESS mode
Sub_containers_and_objects_inherit); Let the self-health inherit his authority; Inheritance mode

Merge the permissions list for the structure EA and Olddacl to the new Newdacl
if (SetEntriesInAcl (1, &ea, NULL, &newdacl)!= error_success)
Goto Cleanup;
Writes the new ACL to the specified key
SetNamedSecurityInfo (Lpobjectname, ObjectType,
Dacl_security_information,
NULL, NULL,
Newdacl,
NULL);
Start Operation Registry//////////////////////////////////////////////////////////
//...................................................
////////////////////////////////////////////////////////////////////////////
The right to restore the registry;
Buildexplicitaccesswithname (&ea,
"Everyone",//Name of Trustee
Generic_read,//type of Access
Set_access,//ACCESS mode
No_inheritance); Let the self-health inherit his authority; Inheritance mode
if (SetEntriesInAcl (1, &ea, NULL, &olddacl)!= error_success)
Goto Cleanup;
Writes the old ACL to the specified key
SetNamedSecurityInfo (Lpobjectname, ObjectType,
Dacl_security_information,
NULL, NULL,
Olddacl,
NULL);
Release pointer
Cleanup:
if (SD!= NULL)
LocalFree ((hlocal) SD);
if (Newdacl!= NULL)
LocalFree ((hlocal) newdacl);
if (Olddacl!= NULL)
LocalFree ((hlocal) olddacl);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.