求高手将一段c++builder代码转成delphi(100分)

  • 主题发起人 主题发起人 jxsbb
  • 开始时间 开始时间
J

jxsbb

Unregistered / Unconfirmed
GUEST, unregistred user!
这是在c++builder研究上的一段代码,可我不懂c++builder,请高手转一下!谢谢了!<br>文章地址:<br>http://www.ccrun.com/article.asp?i=563&amp;d=tshoza<br><br>原文如下:<br><br>本文转自csdn,原作:MEFULEU (新手上路) <br>http://expert.csdn.net/Expert/topic/2194/2194594.xml?temp=.952038<br><br>在2k系统操作注册表时,发现某些健必须要有权限问题;<br>察看各位大大的贴,可惜没有一个合适的结果;<br>有人说:可以提高使用者权限;但是事实上好像不是很好用;<br>经过艰苦.艰苦.艰艰苦苦;终于在msdn上找到了一些好动动;<br>不敢独享,(哎,我可不想某人,好东西藏到自己都忘了的地方)<br>整理出来一些对某些人有用的东西:嘿嘿,代码如下:<br>严重建议:大家都把好东西往上贴吧!!!!!!<br><br>欢迎来信探讨: lanren_me@etang.com<br><br>&nbsp; &nbsp; //开始重新配置使用注册表的权限----------<br><br>&nbsp; &nbsp; LPTSTR lpObjectName;<br>&nbsp; &nbsp; SE_OBJECT_TYPE ObjectType; &nbsp; &nbsp; &nbsp; &nbsp;//#include &lt;aclapi.h&gt;<br><br>&nbsp; &nbsp; PACL OldDACL,NewDACL;<br>&nbsp; &nbsp; PSECURITY_DESCRIPTOR SD;<br>&nbsp; &nbsp; EXPLICIT_ACCESS ea;<br><br>&nbsp; &nbsp; lpObjectName = "MACHINE//SYSTEM//ControlSet001//Enum//Root";<br><br>&nbsp; &nbsp; ObjectType =SE_REGISTRY_KEY;<br><br>&nbsp; &nbsp; //建立一个空的ACL;<br>&nbsp; &nbsp; if (SetEntriesInAcl(0, NULL, NULL, &amp;OldDACL)!=ERROR_SUCCESS)<br>&nbsp; &nbsp; &nbsp; &nbsp; return;<br><br>&nbsp; &nbsp; if (SetEntriesInAcl(0, NULL, NULL, &amp;NewDACL)!=ERROR_SUCCESS)<br>&nbsp; &nbsp; &nbsp; &nbsp; return;<br><br>&nbsp; &nbsp; //获取现有的ACL列表到OldDACL<br>&nbsp; &nbsp; if(GetNamedSecurityInfo(lpObjectName, ObjectType,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DACL_SECURITY_INFORMATION,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL, NULL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;OldDACL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL, &amp;SD) != ERROR_SUCCESS)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application-&gt;MessageBox("指定的键不存在!","提示",MB_OK);<br><br>&nbsp; &nbsp; //设置用户名"Everyone"对指定的键有所有操作权到结构ea<br>&nbsp; &nbsp; ZeroMemory(&amp;ea, sizeof(EXPLICIT_ACCESS));<br><br>&nbsp; &nbsp; BuildExplicitAccessWithName(&amp;ea,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Everyone", &nbsp; &nbsp; &nbsp;// name of trustee<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GENERIC_ALL, &nbsp; &nbsp; // type of access<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET_ACCESS, &nbsp; &nbsp; &nbsp;// access mode<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SUB_CONTAINERS_AND_OBJECTS_INHERIT); //让自健继承他的权限; inheritance mode<br>// 本文转自 C++Builder研究 - http://www.ccrun.com/article.asp?i=563&amp;d=tshoza<br><br>&nbsp; &nbsp; <br>&nbsp; &nbsp; //合并结构ea和OldDACL的权限列表到新的NewDACL<br>&nbsp; &nbsp; if(SetEntriesInAcl(1, &amp;ea, NULL, &amp;NewDACL) != ERROR_SUCCESS)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; goto Cleanup;<br><br>&nbsp; &nbsp; //把新的ACL写入到指定的键<br>&nbsp; &nbsp; SetNamedSecurityInfo(lpObjectName, ObjectType,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DACL_SECURITY_INFORMATION,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL, NULL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NewDACL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL);<br><br><br>&nbsp; &nbsp; ///////开始操作注册表//////////<br>&nbsp; &nbsp; //..........<br>&nbsp; &nbsp; //////////<br><br>&nbsp; &nbsp; //恢复注册表的权限;<br><br>&nbsp; &nbsp; BuildExplicitAccessWithName(&amp;ea,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Everyone", &nbsp; &nbsp; &nbsp;// name of trustee<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GENERIC_READ, &nbsp; &nbsp; // type of access<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET_ACCESS, &nbsp; &nbsp; &nbsp;// access mode<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NO_INHERITANCE); //让自健继承他的权限; inheritance mode<br><br>&nbsp; &nbsp; if(SetEntriesInAcl(1, &amp;ea, NULL, &amp;OldDACL) != ERROR_SUCCESS)<br>&nbsp; &nbsp; &nbsp; &nbsp;goto Cleanup;<br><br>&nbsp; &nbsp; //把旧的ACL写入到指定的键<br>&nbsp; &nbsp; SetNamedSecurityInfo(lpObjectName, ObjectType,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DACL_SECURITY_INFORMATION,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL, NULL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OldDACL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL);<br><br>&nbsp; &nbsp; &nbsp; &nbsp;//释放指针<br>&nbsp; &nbsp; Cleanup:<br>&nbsp; &nbsp; if(SD != NULL)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LocalFree((HLOCAL) SD);<br>&nbsp; &nbsp; if(NewDACL != NULL)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LocalFree((HLOCAL) NewDACL);<br>&nbsp; &nbsp; if(OldDACL != NULL)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LocalFree((HLOCAL) OldDACL);
 
后退
顶部