Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 158265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:39:04+00:00 2026-05-11T10:39:04+00:00

I am trying to write a simple function for windows that answers the following

  • 0

I am trying to write a simple function for windows that answers the following question.

Does user (U) have rights (R) on file (F)?
Where,
   R is some combination of (GENERIC_READ, GENERIC_WRITE, GENERIC_EXECUTE)
   U does not have to be logged in or impersonated

The code that I wrote is shown below. The application calls the first UserHasPermission that is shown.

The access rights returned by GetEffectiveRightsFromAcl are the same for all user/file combinations that I tested ($001200A9). I double checked and $001200A9 is not just a pointer to the location where the access rights are actually stored.

My question is twofold:
1. Is there a better way of doing this?
2. Can anyone tell me where I am going wrong?

 function UserHasPermission(APermission: Longword; out HasPermission: Boolean; AFileName: WideString; AUserName: String; ADomainName: String): Boolean;     var       SID: PSID;       ACL: PACL;     begin       SID := nil;       ACL := nil;       try         Result := GetUserSID(SID, AUserNAme, ADomainName);         Result := Result and GetFileDACL(AFileName, ACL);         Result := Result and UserHasPermission(APermission, HasPermission, ACL, SID);       finally         Dispose(SID);       end;     end;      function UserHasPermission(APermission: Longword; out HasPermission: Boolean; AACL: PACL; AUserSID: PSID): Boolean;     var       T: TRUSTEE;       Rights: ACCESS_MASK;     begin       BuildTrusteeWithSid(@T, AUserSID);       Result := GetEffectiveRightsFromAcl(AACL, @T, @Rights) = ERROR_SUCCESS;       HasPermission := (Rights and APermission) = APermission;     end;      function GetUserSID(out ASID: PSID; AUserName: WideString; const ADomainName: WideString): Boolean;     var       NSID, NDomain: Longword;       Use: SID_NAME_USE;       DomainName: WideString;     begin       Result := False;       if Length(AUserName) > 0 then         begin           if Length(ADomainName) > 0 then             AUserName := ADomainName + '\' + AUserName;            // determine memory requirements           NSID := 0;           NDomain := 0;           LookupAccountNameW(nil, PWideChar(AUserName), nil, NSID, nil, NDomain, Use);            // allocate memory           GetMem(ASID, NSID);           SetLength(DomainName, NDomain);            Result := LookupAccountNameW(nil, PWideChar(AUserName), ASID, NSID, PWideChar(DomainName), NDomain, Use);         end;     end;      function GetFileDACL(AFileName: WideString; out AACL: PACL): Boolean;     var       SD: PSecurityDescriptor;       NSD, NNeeded: Longword;       Present, Defualted: Longbool;     begin       GetFileSecurityW(PWideChar(AFileName), DACL_SECURITY_INFORMATION, nil, 0, NNeeded);       GetMem(SD, NNeeded);       try         NSD := NNeeded;         Result := GetFileSecurityW(PWideChar(AFileName), DACL_SECURITY_INFORMATION, SD, NSD, NNeeded);         Result := Result and GetSecurityDescriptorDacl(SD, Present, AACL, Defualted);         Result := Result and Present;       finally         Dispose(SD);       end;     end; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:39:04+00:00Added an answer on May 11, 2026 at 10:39 am

    GetEffectiveRightsFromAcl are the same for all user/file combinations that I tested ($001200A9).

    That all depends on the ACL, e.g. if Everyone is granted full control then any use will have full control.

    The code looks reasonable, and you are using one of the Win32 security APIs (GetEffectiveRightsFromAcl) to do the heavy lifting.

    Suggestion: Create very specific ACLs to test your code (SDDL makes this easier), starting with one that makes no grants, then one that only includes a different user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Have a look at the SqlBulkCopy class - this allows… May 11, 2026 at 11:54 am
  • added an answer Depends on how you want your application to behave. First,… May 11, 2026 at 11:54 am
  • added an answer Perhaps something like this? <% @objects.each do |obj| %> <%… May 11, 2026 at 11:54 am

Related Questions

I am trying to write a really simple Outlook VSTO add in that checks
I am trying to write a console app that simply lists the number of
I am trying to write a unit test for an action method which calls
I am trying to write a servlet that will send a XML file (xml
I am trying to write a regular expression to strip all HTML with the
I am trying to write a Windows Form and ASP.NET C# front-end and MSAccess
I am trying to write a stored procedure which selects columns from a table
I am trying to write a replacement regular expression to surround all words in
I am trying to write a query for SQL Server 2005 but I can't
I am trying to write a decorator to do logging: def logger(myFunc): def new(*args,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.