Discussion:
Unabled to write to registry as restricted user
(too old to reply)
b***@gmail.com
2006-08-23 13:51:19 UTC
Permalink
Raw Message
I have developed a small system-wide hook to write to the registry
exactly what kind of shut down is occuring. This works fine when an
Administrator user is logged in, but when a restricted user is logged
in, it does not work fine. This seems odd because I'm writing to a key
in HKEY_CURRENT_USER/Software/Microsoft/Windows/Explorer, which I can
easily open up in regedit and add/edit as a restricted user.

Here is the part of my code that writes to the registry

function WriteRegRestartVal(newVal: dword) : boolean;
var Reg: TRegistry;
begin
result := false;
Reg := TRegistry.Create(KEY_WRITE);
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer',
True) then
begin
Reg.WriteInteger('HookShutdownType', newVal);
Reg.WriteInteger('Hookwork', 1);
result := true;
end;
Reg.CloseKey;
Reg.Free;
end;

Neither value gets written even if they exist or not. Does anyone have
any insight on this?
Stanley Xu
2006-08-23 14:17:23 UTC
Permalink
Raw Message
Try this line before calling Registry.OpenKey(...)

Registry.Access := KEY_READ or KEY_WRITE;
b***@gmail.com
2006-08-24 12:24:01 UTC
Permalink
Raw Message
Post by Stanley Xu
Try this line before calling Registry.OpenKey(...)
Registry.Access := KEY_READ or KEY_WRITE;
Doh, Looks like that code was working fine. It was just not being
hooked corrected as a restricted user! Everything's good now that I ran
the hooking mechanism as a super user. Sorry about that!
Riki Wiki
2006-08-26 06:36:54 UTC
Permalink
Raw Message
Hoi Ben

For next time you post consider using the newsgroup b.p.d.nativeapi.win32.

How to post to Delphi newsgroups:
<http://delphi.wikia.com/wiki/Delphi_Newsgroups>

Loading...