1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Access Violation Trying to modify folder's permissions

Discussion in 'Delphi Programming' started by delphiy, Oct 31, 2015.

  1. delphiy
    Offline

    delphiy DF Member

    Hello guys,
    I'm trying to make a little bit of code to create a folder and allow everyone modify access to the folder and its sub-directories. So far I have this code here :Code:
    PHP:
    unit ModifyPerms;

    interface

    uses
      Windows
    MessagesSysUtilsClassesGraphicsControlsFormsDialogs,
      
    StdCtrlsAccCtrlperms;

    type
      TForm1 
    = class(TForm)
        
    Button1TButton;
        
    procedure Button1Click(SenderTObject);

      private
        { Private 
    declarations }
      public
        { Public 
    declarations }
      
    end;

    var
      
    Form1TForm1;

    implementation
    {$R *.DFM}

    procedure TForm1.Button1Click(SenderTObject);
    var
      
    NewDaclOldDaclPACl;
      
    SDPSECURITY_DESCRIPTOR;
      
    EAPEXPLICIT_ACCESS_A;
    begin
      GetNamedSecurityInfo
    (PChar('c:\test'), SE_FILE_OBJECT,
    DACL_SECURITY_INFORMATIONnilnil, @OldDaclnilSD);

      
    BuildExplicitAccessWithName(@EAPChar('Everyone'), GENERIC_ALL,
    GRANT_ACCESSSUB_CONTAINERS_AND_OBJECTS_INHERIT);

      
    SetEntriesInAcl(1, @EAOldDaclNewDacl);

      
    SetNamedSecurityInfo(PChar('c:\test'), SE_FILE_OBJECT,
    DACL_SECURITY_INFORMATIONnilnilNewDaclnil);
    end;

    end.
    I'm using Delphi 5 (I know it's old as crap, no I can't just upgrade to a newer Delphi). When I run it tells me "Project ModifyPermissions.exe raised exception class EAccessViolation with message 'Access violation at address 00000001. Read of address 00000001'. Process stopped. Use Step or Run to continue.

    I tried running the program in admin mode, it doesn't change anything. I'm confused since I got this code from someone who's program was working... Any help would be appreciated, thanks in advance! [​IMG]
     
  2. paruba
    Offline

    paruba DF Member

    For this operation you must first run application with elevate privileges on Windows Vista and above...

    Another idea is to use Windows "icacls" command. Seach on Google about icacls ...

    Hope to be helpfull...
     
     
  3. digitallan
    Online

    digitallan Guest

    i am maybe little late but you can use like this

    procedure TForm1.Button1Click(Sender: TObject);
    var
      NewDacl, OldDacl,Sacl: PACL;
      SD: PSECURITY_DESCRIPTOR;
      EA: PEXPLICIT_ACCESS_A;
      SidOwner: PSID;
      SidGroup: PSID;
    begin
      GetNamedSecurityInfo(PChar('c:\test'), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, @SidOwner, @SidGroup, @OldDacl, @Sacl, SD);
      BuildExplicitAccessWithName(@EA, PChar('Everyone'), GENERIC_ALL,GRANT_ACCESS, SUB_CONTAINERS_AND_OBJECTS_INHERIT);
      SetEntriesInAcl(1, @EA, OldDacl, NewDacl);
      SetNamedSecurityInfo(PChar('c:\test'), SE_FILE_OBJECT,DACL_SECURITY_INFORMATION, SidOwner, SidGroup, NewDacl, Sacl) ;
      LocalFree(HLOCAL(SD));
    end;
     
  4. johnd9
    Online

    johnd9 Guest

    @digitallan: Is this going to work also for newly created users? 
     

Share This Page