注册表操作权限的问题,请指点...(100分)

Z

z9945

Unregistered / Unconfirmed
GUEST, unregistred user!
如果我以USERS组身份登录WIN2K时运行程序不能读写注册表中<br>HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/run中的信息<br>(因为要做到让用户选择是否自动运行该程序),<br>我在网上看到一个关机的程序用了提升权限的API函数AdjustTokenPrivileges,<br>我是不也可以用它?怎么样用啊?
 
两回事了
 
没有权限,你得用REG API来访问,我以前写过一个,不过丢了。<br>不然你先这样试试:<br>&nbsp; reg := TRegister.Create(KEY_READ);<br>&nbsp; ...<br>OpenKey时,/Software/Microsoft/Windows/CurrentVersion/run/,最后面要有一个"/",不要少了它<br><br>不行的话,看着那TRegistery类一点点自已写API。<br>
 
With TRegistry.Create do<br>&nbsp; begin<br>&nbsp; Rootkey :=HKEY_CLASSES_ROOT;<br>&nbsp; OpenKey(Software/Microsoft/Windows/CurrentVersion/run/,true);<br>&nbsp; WriteString('SSSSS','SSSSS');<br>&nbsp; CloseKey;<br>&nbsp; Free;<br>&nbsp; end;
 
copy_paste:<br>你的方法可以读出来了,但写进去不行.
 
权限是NT给你分配的,你试试给这个用户分配一个读注册表的权限,一般来说如果只是:user,只能读Current_User那里面的东东
 
bigroute:<br>你写的在USERS组下是不行的,我开始也是用这.
 
那该用什么办法?<br>上级就给USERS级权限,但要实现该功能...
 
&gt;&gt;在网上看到一个关机的程序用了提升权限的API函数AdjustTokenPrivileges,<br>其实这个“提升”还是需要当前系统策略已经允许该用户/组进行此操作,如果该用户本来就没有读写此部分的权限,那么什么都不管用。<br>以下内容供参考<br>Project JEDI Code Library (JCL) <br>ftp://delphi-jedi.org/Code_Library/Release_1_11/JCL.zip<br><br>Project JEDI ACLAPI, ACLUI头文件 <br>(JwaAclUI.pas, JwaAclApi.pas) - ftp://delphi-jedi.org/api/Win32API.zip<br><br>JCL 中有一个JclSecurity.pas unit,有一个函数叫做AllowRegKeyForEveryone就是干这个<br>事情的,我调试通过<br><br>function AllowRegKeyForEveryone(Key: HKEY; Path: string): Boolean;<br>var<br>&nbsp; WidePath: PWideChar;<br>&nbsp; Len: Integer;<br>begin<br>&nbsp; case Key of<br>&nbsp; &nbsp; HKEY_LOCAL_MACHINE:<br>&nbsp; &nbsp; &nbsp; Path := 'MACHINE/' + Path;<br>&nbsp; &nbsp; HKEY_CURRENT_USER:<br>&nbsp; &nbsp; &nbsp; Path := 'CURRENT_USER/' + Path;<br>&nbsp; &nbsp; HKEY_CLASSES_ROOT:<br>&nbsp; &nbsp; &nbsp; Path := 'CLASSES_ROOT/' + Path;<br>&nbsp; &nbsp; HKEY_USERS:<br>&nbsp; &nbsp; &nbsp; Path := 'USERS/' + Path;<br>&nbsp; end;<br>&nbsp; Len := (Length(Path)+1)*SizeOf(WideChar);<br>&nbsp; GetMem(WidePath,Len);<br>&nbsp; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, PChar(Path), -1, WidePath, Len);<br>&nbsp; Result := SetNamedSecurityInfoW(WidePath, SE_REGISTRY_KEY,<br>&nbsp; &nbsp; DACL_SECURITY_INFORMATION, nil, nil, nil, nil) = ERROR_SUCCESS;<br>&nbsp; FreeMem(WidePath);<br>end;<br><br>SetNamedSecurityInfo函数设置特定securable object的security descriptor, 是Access Control API,<br>在下载的Jed Object Pascal API Library里面声明了,给你这个函数对不起你,我跟你谈<br>谈我花了一晚上了解的冬冬吧。<br><br>&nbsp; &nbsp; SID(Security identifiers) 是一个可变记录体, 用于Windows NT的安全模型,它的主<br>要功能是定义安全对象(identify security subjects, 泛指包含了security descriptor的<br>对象, 用户进程, 注册表, 文件等等这些冬冬), 一方面SID是一个通用而强大的系统权限控<br>制方式,另一方面,SID太TMD的复杂了。<br><br>&nbsp; &nbsp; SID的主要功能<br>- 获取用户、用户组可以使用到的对象(securable object)<br>- 获得访问特别的对象的权限,Access Control List(ACL)就是干这个冬冬的,<br>&nbsp; ACL由Access Control Entries(ACE)组成,ACE就是由SID和Access Flags<br>&nbsp; 共同标记的记录机构。<br>- 等等等等(我都懒得仔细看下去)<br><br>&nbsp; &nbsp; SID通常以字符串的形式保存,比如EVERYONE用户的SID通常为('S-1-1-0'), 它可能存<br>储在文件里面, 也可能存储在注册表(比如HKEY_USERS下面的键名), 甚至通过文件夹的名字<br>(看看Windows回收站RECYCLER的子目录)来保存。所以,一般情况下面(什么是特殊情况我也<br>没有搞明白), 我们使用字符串访问SID, Windows API提供了函数用于SID和String之间相互<br>转换的函数(LookupAccountSid, LookupAccountName), 下面是一些常用的SID字符串标记<br><br>Everyone &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;S-1-1-0<br>NT Authority &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;S-1-5<br>Dialup &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;S-1-5-1<br>Network &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S-1-5-2<br>Batch &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S-1-5-3<br>Interactive &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S-1-5-4<br>Service &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S-1-5-6<br>AnonymousLogon &nbsp; &nbsp; &nbsp; &nbsp;S-1-5-7 &nbsp; &nbsp; &nbsp; (aka null logon session)<br>Proxy &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S-1-5-8<br>ServerLogon &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S-1-5-9 &nbsp; &nbsp; &nbsp; (aka domain controller account)<br>Self &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;S-1-5-10 &nbsp; &nbsp; &nbsp;(self RID)<br>Authenticated User &nbsp; &nbsp;S-1-5-11 &nbsp; &nbsp; &nbsp;(Authenticated user somewhere)<br>Restricted Code &nbsp; &nbsp; &nbsp; S-1-5-12 &nbsp; &nbsp; &nbsp;(Running restricted code)<br>Terminal Server &nbsp; &nbsp; &nbsp; S-1-5-13 &nbsp; &nbsp; &nbsp;(Running on Terminal Server)<br>Remote Logon &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;S-1-5-14 &nbsp; &nbsp; &nbsp;(Remote Interactive Logon)<br>(Logon IDs) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S-1-5-5-X-Y<br>(NT non-unique IDs) &nbsp; S-1-5-0x15-...<br>(Built-in domain) &nbsp; &nbsp; s-1-5-0x20<br><br>&nbsp; &nbsp; 这些定义并不一定是标准, 比如俄文版Windows 2000就会有所区别, 也许中文版也会有<br>些不同(我用的是英文版Win2000, 完全一样)<br><br>&nbsp; &nbsp; 当用户登陆进入Windows NT/2000/XP系统, 正确输入用户名和密码, 成功的话, 系统创<br>建一个Access token, 而这个用户运行的每个进程都自动制作一个Access token的副本, <br>Access token包括SID信息用以指明用户是那个用户和隶属于那个用户组, Access token也<br>包含了用户或用户组的privileges list(特权列表), 当用户进程需要使用系统对象的时候, <br>系统通过进程的SID判断进程隶属于那个用户, 当用户需要执行一些系统任务的时候, 系统<br>通过进程的privileges来判断, 比如执行关机ExitWindows函数. 看到这里, 兄弟应该明白<br>NT下的关机程序和NT下的注册表处理程序是两个完全不同的概念了吧, 关机是添加privileges<br>特权, 注册表作为一个系统对象, 需要的是修改security descriptor.<br>
 
傻傻的问题:<br>[Error] Unit1.pas(44): Undeclared identifier: 'SE_MACHINE_KEY'<br>怎么声明?
 
使用reg的文本文件就可以了,我早就用过了!<br>
 
从文件导入?
 
http://www.delphibbs.com/delphibbs/DispQ.asp?LID=1354567<br>关注一下吧没有人提起来呀!用MODEM打电话利用PC机的耳机和麦克风,自己编程如何实现?<br>(我知道有现成的软件可以用,但是我想自己实现这个上东西)<br>QQ:65466700<br>MAIL: along@b2sun.com<br>TEL :13802785865<br>http://b2sun.com<br>请各位大侠多多指教!<br><br>
 
我不会这个问题
 
<br>为了引起注意:<br><br>to yzhshi:<br>to yzhshi:<br>to yzhshi:<br>to yzhshi:<br>to yzhshi:<br><br>SE_REGISTRY_KEY的类型和实际的数值是什么???<br>
 
没人理,OVER吧
 
顶部