Can registry be protected in 95/NT?

Is it possible to prevent users programs
(for example a Delphi program)
 from writing to registry in 95 and NT?

Regards,
Morten
LVL 1
mdrastedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JaymolCommented:
You can set security permissions with a program called RegEdt32 (*NOT* regedit).  Just set the security to read-only for everyone except administrators.  (I'm not sure if this program is available in 95/98.  This is for NT.)

John.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwilson032697Commented:
No so far as I know!

Cheers,

Raymond.
0
BoRiSCommented:
mdrasted

The only way I know is to block users from opening the registry using windows polices... You can not protect the registry(read only) as the registry is constantly updated by windows it's self...

I may be wrong, so I'm following on this one ;-)

Later
BoRiS
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

simonetCommented:
Only as Boris suggested: by using the Policy Editor that comes as part of the Win9x Resource Kit.

The Policy Editor will let you define (on  a per-user basis) who can and who can't access the Registry directly.

Other than that it's impossible. If you need lots of security on the Registry for your users, you should consider using Windows NT Workstation, not Windows 9x.

Alex
0
JaymolCommented:
Err...Hello?  I AM TOO QUIET???
0
MadshiCommented:
If we're talking about win32 API, you can't do anything under win9x (except what PolEdit does, but that's not enough). Under winNT you can call "Set(Named)SecurityInfo(..., SE_REGISTRY_KEY, ...)" to set the accesses that specific users have.

If you want a more perfect solution you will have to build little drivers for both NT and win9x. Look at "www.sysinternals.com". There you can download a little utility (with sources) called "RegMon" which monitors all registry actions. With some changes you can extend the functionality to deny registry changes. But this all happens at driver level, so you can't use Delphi for that purpose.

Regards, Madshi.
0
mdrastedAuthor Commented:
Thanks everybody for helping me,

But I think it's Jaymol who helped me the most. So Jaymol, please submit your comment as an answer.

Regards,
Morten

0
rwilson032697Commented:
Ahem - The code below will work for NT, but not for 95. Does this help?

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

const SECURITY_NULL_SID_AUTHORITY = 0;
      SECURITY_WORLD_SID_AUTHORITY = 1;
      SECURITY_LOCAL_SID_AUTHORITY = 2;
      SECURITY_CREATOR_SID_AUTHORITY = 3;
      SECURITY_NT_AUTHORITY = 5;

      SECURITY_INTERACTIVE_RID = $00000004;
      SECURITY_BUILTIN_DOMAIN_RID = $00000020;
      DOMAIN_ALIAS_RID_ADMINS = $00000220;

      ACL_REVISION = 2;
      SECURITY_DESCRIPTOR_REVISION = 1;

type
      PACE_Header = ^TACE_Header;
      TACE_Header = record
        AceType: BYTE;
        AceFlags: BYTE;
        AceSize: WORD;
      end;

      PAccess_Allowed_ACE = ^TAccess_Allowed_ACE;
      TAccess_Allowed_ACE = record
        Header: TACE_Header;
        Mask: ACCESS_MASK;
        SidStart: DWORD;
      end;

implementation

{$R *.DFM}

function do_it: boolean;
var sia: TSIDIdentifierAuthority;
    pInteractiveSid, pAdministratorsSid: PSID;
    sd: Windows.TSecurityDescriptor;
    pDacl: PACL;
    dwAclSize: DWORD;
    aHKey: HKEY;
    lRetCode: longint;
    bSuccess: boolean;
begin

    sia.Value[0] := 0;
    sia.Value[1] := 0;
    sia.Value[2] := 0;
    sia.Value[3] := 0;
    sia.Value[4] := 0;
    sia.Value[5] := SECURITY_NT_AUTHORITY;
    pInteractiveSid := nil;
    pAdministratorsSid := nil;
    pDacl := nil;

    bSuccess := false; // assume this function fails

    //
    // open the key for WRITE_DAC access
    //
    lRetCode := RegOpenKeyEx(
      HKEY_CURRENT_USER,
      'SOFTWARE\Test',
      0,
      WRITE_DAC,
      aHKey
      );

    if(lRetCode <> ERROR_SUCCESS) then begin
      ShowMessage('Error in RegOpenKeyEx');
      result := false;
    end;

    //
    // prepare a Sid representing any Interactively logged-on user
    //
    if( not AllocateAndInitializeSid(
      sia,
      1,
      SECURITY_INTERACTIVE_RID,
      0, 0, 0, 0, 0, 0, 0,
      pInteractiveSid
      )) then begin
        ShowMessage('Error in: AllocateAndInitializeSid');
        //goto cleanup;
    end;

    //
    // prepare a Sid representing the well-known admin group
    //
    if(not AllocateAndInitializeSid(
      sia,
      2,
      SECURITY_BUILTIN_DOMAIN_RID,
      DOMAIN_ALIAS_RID_ADMINS,
      0, 0, 0, 0, 0, 0,
      pAdministratorsSid
      )) then begin
        ShowMessage('Error in: AllocateAndInitializeSid');
        // goto cleanup;
    end;

    //
    // compute size of new acl
    //
    dwAclSize := sizeof(TACL) +
      2 * ( sizeof(TAccess_Allowed_ACE) - sizeof(DWORD) ) +
      GetLengthSid(pInteractiveSid) +
      GetLengthSid(pAdministratorsSid) ;

    //
    // allocate storage for Acl
    //
    pDacl := PACL(HeapAlloc(GetProcessHeap(), 0, dwAclSize));
    //if(pDacl == nil) goto cleanup;

    if( not InitializeAcl(pDacl^, dwAclSize, ACL_REVISION)) then begin
        ShowMessage('Error in: InitializeAcl');
        //goto cleanup;
    end;

    //
    // grant the Interactive Sid KEY_READ access to the perf key
    //
    if(not AddAccessAllowedAce(
      pDacl^,
      ACL_REVISION,
      KEY_READ,
      pInteractiveSid
      )) then begin
        ShowMessage('Error in: AddAccessAllowedAce');
        //goto cleanup;
    end;

    //
    // grant the Administrators Sid KEY_ALL_ACCESS access to the perf key
    //
    if(not AddAccessAllowedAce(
      pDacl^,
      ACL_REVISION,
      KEY_ALL_ACCESS,
      pAdministratorsSid
      )) then begin
        ShowMessage('Error in: AddAccessAllowedAce');
        //goto cleanup;
    end;

    if(not InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION)) then begin
      ShowMessage('Error in: InitializeSecurityDescriptor');
      //goto cleanup;
    end;

    if(not SetSecurityDescriptorDacl(@sd, TRUE, pDacl, FALSE)) then begin
      ShowMessage('Error in: SetSecurityDescriptorDacl');
      //goto cleanup;
    end;

    //
    // apply the security descriptor to the registry key
    //
    lRetCode := RegSetKeySecurity(
      aHKey,
      SECURITY_INFORMATION(DACL_SECURITY_INFORMATION),
      @sd
      );

    if(lRetCode <> ERROR_SUCCESS) then begin
      ShowMessage('Error in: RegSetKeySecurity');
      //goto cleanup;
    end;

    bSuccess := TRUE; // indicate success

end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  do_it;
end;



end.


(credit to freter)

Cheers,

Raymond.
0
yk030299Commented:
listen
0
freterCommented:
hi all,

one thing i'd like to add:

it is NOT TRUE (= false), that policies can prevent access to the registry. there is a policy that reads "disable registry editing tools", but this setting is only read by regedit.exe and regedt32.exe! if you write your own tool to write to the registry, you can have FULL access to the registry even if this policy is active!!!

so, the only possibility to prevent applications from writing to the registry is writing a driver, just as madshi stated, or to set the security acls using regedt32 or the code that raymond posted. both options will only work on windows nt. if you choose option #1, you can decide which applications gain write access, whereas option #2 will give you the ability to decide which users will be able to write / read the registry. i recommend using option #2 (it's easier :-) )

just my $0.02

</freter>
0
MadshiCommented:
Hi freter...   :-)
You're right, except one thing: Writing a driver that takes care of the registry accesses is also possible for win9x...   :-)

Regards, Madshi.
0
freterCommented:
yep. but writing drivers is no fun.
</freter>
0
MadshiCommented:
Yep, mainly because we can't do it in Delphi...   :-)   :-(
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.