在Win2k下操纵有权限限制的注册表键
在2k系统操纵注册表时,发明某些健必需要有权限问题;
察看列位大大的贴,惋惜没有一个符合的功效;
有人说:可以提高利用者权限;可是事实上仿佛不是很好用;
颠末费力.费力.艰费力苦;终于在msdn上找到了一些好动动;
不敢独享,(哎,我可不想或人,好对象藏到本身都忘了的处所)
整理出来一些对某些人有用的对象:嘿嘿,代码如下:
严重发起:各人都把好对象往上贴吧!!!!!!
接待来信探讨: [email protected]
//开始从头设置利用注册表的权限------------------------------------------------
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;
//成立一个空的ACL;
if (SetEntriesInAcl(0, NULL, NULL, &OldDACL)!=ERROR_SUCCESS)
return;
if (SetEntriesInAcl(0, NULL, NULL, &NewDACL)!=ERROR_SUCCESS)
return;
//获取现有的ACL列表到OldDACL
if(GetNamedSecurityInfo(lpObjectName, ObjectType,
DACL_SECURITY_INFORMATION,
NULL, NULL,
&OldDACL,
NULL, &SD) != ERROR_SUCCESS)
Application->MessageBox("指定的键不存在!","提示",MB_OK);
//配置用户名"Everyone"对指定的键有所有操纵权到布局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); //让自健担任他的权限; inheritance mode
//归并布局ea和OldDACL的权限列表到新的NewDACL
if(SetEntriesInAcl(1, &ea, NULL, &NewDACL) != ERROR_SUCCESS)
goto Cleanup;
//把新的ACL写入到指定的键
SetNamedSecurityInfo(lpObjectName, ObjectType,
DACL_SECURITY_INFORMATION,
NULL, NULL,
NewDACL,
NULL);
///////开始操纵注册表//////////////////////////////////////////////////////////
//...................................................
////////////////////////////////////////////////////////////////////////////
//规复注册表的权限;
BuildExplicitAccessWithName(&ea,
"Everyone", // name of trustee
GENERIC_READ, // type of access
SET_ACCESS, // access mode
NO_INHERITANCE); //让自健担任他的权限; inheritance mode
if(SetEntriesInAcl(1, &ea, NULL, &OldDACL) != ERROR_SUCCESS)
goto Cleanup;
//把旧的ACL写入到指定的键
SetNamedSecurityInfo(lpObjectName, ObjectType,
DACL_SECURITY_INFORMATION,
NULL, NULL,
OldDACL,
NULL);
//释放指针
Cleanup:
if(SD != NULL)
LocalFree((HLOCAL) SD);
if(NewDACL != NULL)
LocalFree((HLOCAL) NewDACL);
if(OldDACL != NULL)
LocalFree((HLOCAL) OldDACL);