Link to home
Start Free TrialLog in
Avatar of Jaymol
Jaymol

asked on

Security Permissions on NT4

How can I change the security permissions of a registry key on Windows NT4?  I can do it within Regedt32.exe, but want to do it programatically from within Delphi.
Avatar of logosapience
logosapience

If you can do it within Regedt32, you can use the TRegistry class
Hi Jaymol, maybe you should try this component. It is a replacement for TRegistry and may be excactly what you are looking for:

http://www.jgsoftware.com/files/djntreg.zip


Regards,

Epsylon.
Avatar of Jaymol

ASKER

Unfortunately, regedit and regedt32 are NOT the same program.  Regedt32 allows changes on Security permissions whereas using regedit or TRegistry does not allow this.  I am adept in manipulating the registry as far as entries go, but this is a matter not covered by the TRegistry class.  If I am incorrect in this, then I would appreciate an example of how security permissions can be changed with TRegistry.
Avatar of Jaymol

ASKER

Since submitting this question, I have found a route around the problem by opening "regedt32.exe" and sending keypresses to make the appropriate changes.  But, if anyone can answer the question anyway, I would be very grateful.
Avatar of Jaymol

ASKER

Can ANYONE answer this question successfully??????
Looked at SetNamedSecurityInfo. It is described in the win32.hlp file, but it is not in Delphi's help context. So you need to open win32.hlp file manually and look in the index for this function.

Regards, Madshi.
Avatar of Jaymol

ASKER

Could you give me an example?  I can't figure out how to use it properly.
Well, I didn't try it, but it should work like this:

// enum types in Delphi are commonly 1 byte long, in win32 API these types are mostly 4 bytes long, so we must switch the compiler settings
{$minenumsize 4}
type TObjType = (SE_UNKNOWN, SE_FILE, SE_SERVICE, SE_PRINTER, SE_REGISTRY, SE_LMSHARE, SE_KERNEL, SE_WINDOW);
{$minenumsize 1}

function SetNamedSecurityInfo(objName: PWideChar; objType: TObjType; SecInfo: dword; pSIDOwner,pSIDGroup: PSID; ppDacl,ppSacl: PACL) : dword; stdcall;
         external 'advapi.dll' name 'SetNamedSecurityInfoW';

function AllowRegKeyForEveryone(key: hkey; path: string) : boolean;
  case key of
    HKEY_LOCAL_MACHINE : path:='MACHINE\'     +path;
    HKEY_CURRENT_USER  : path:='CURRENT_USER\'+path;
    HKEY_CLASSES_ROOT  : path:='CLASSES_ROOT\'+path;
    HKEY_USERS         : path:='USERS\'       +path;
  end;
  result:=SetNamedSecurityInfo(pwidechar(wideString(path)),SE_REGISTRY_KEY,DACL_SECURITY_INFORMATION,nil,nil,nil,nil)=0;
end;

  if AllowRegKeyForEveryone(HKEY_LOCAL_MACHINE,'Software') then ...

This example simply gives in a new nil dacl. A nil dacl means that everyone has access. If you want to give specific accesses to specific users, you'll have to create a custom dacl.

Regards, Madshi.
Avatar of Jaymol

ASKER

Madshi, could you submit that as an answer?  I wanna give you the points you deserve.
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial