Jump to content
FredAI

Set Acl permissions UDF

Recommended Posts

@AdamUL I'm only interested who has access - like groups and users - not what the access is. I can read that from the name of the groups. So if it is possible just to find the groups with this UDF, it would be great.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

I have written a skript to get the ACL listing and display the result in a TreeView.
It's about 10 years old, written in German and uses the old Excel UDF - so it definitely needs a brush up.
But if you are interested ...


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-07-21 - Version 1.5.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Since 2011 the scripting world has evolved a lot !

In Powershell this is 6 lines of code and runs lightning fast...

If you persist in using AutoIT, you can run the PS code using the .NET Common Language Runtime (CLR) Framework

If you are interested ...

 


Share this post


Link to post
Share on other sites

@Valnurat  Here is you an example, using the UDF.  

#include <Debug.au3>
#include <Security.au3>
#include 'Permissions.au3'

Global $sFile = @ScriptDir & '\test.txt'
FileWrite($sFile, 'test')
MsgBox(0, "File", "Created")

_InitiatePermissionResources()

;Get the file's DACL.
;Do not include inherited permissions.
;~ $pDACL = _GetObjectDacl($sFile)
;~ If @error Then Exit MsgBox(16, "ERROR", "Error _GetObjectDacl")

;Include inherited permissions.
$pDACL = _GetObjectDaclIncludeInherit($sFile)
If @error Then MsgBox(16, "ERROR", "Error _GetObjectDaclIncludeInherit")

;Create an empty array to fill with the DACL read from the object.
Global $aPerm[0][4]
$iRet = _MergeDaclToArray($pDACL, $aPerm)
;If there are no explicit permissions, and only inherited, the return valuse will be 0, if you used _GetObjectDacl.  
MsgBox(0, '', '_MergeDaclToArray return value: ' & $iRet)
If $iRet = 0 Then Exit 2

;SIDs are DLL structs so they show up as blank strings in the array.  Pemissions show up as signed integers. 
;$array[n][0] - SID structure. 
;$array[n][1] - The access type. A value of 1 grants acecess, 0 denies access.
;$array[n][2] - The access mask. 

_DebugArrayDisplay($aPerm, $sFile)

;Show users and groups in the DACL array as strings.
Global $aAcct
Global $pAcct
Global $sAcct
For $i = 0 To UBound($aPerm, 1) - 1 
    
    $pAcct = DllStructGetPtr($aPerm[$i][0])
    
    ;Convert SIDs to users and groups strings.  
    $aAcct = _Security__LookupAccountSid($pAcct)
    If Not IsArray($aAcct) Then 
        $aPerm[$i][0] = _Security__SidToStringSid($pAcct) ;Put SID string for unknown SID.
        ContinueLoop
    EndIf
    $sAcct = ($aAcct[1] <> "" ? $aAcct[1] & "\" : "" ) & $aAcct[0]
    
    ConsoleWrite($sAcct & "  _Security__IsValidSid: " & _Security__IsValidSid($pAcct) & @CRLF)
    
    ;Replace struct with string.  
    $aPerm[$i][0] = $sAcct
    
Next

_ClosePermissionResources()

;User and group names changed to strings to be viewable and searchable.  
_DebugArrayDisplay($aPerm, $sFile)

FileDelete($sFile)
MsgBox(0, "File", "Deleted")

@ptrex  I would like to see and example using Powershell.  If possible, I would like to see how to get the users' or groups' specific permissions.  Thanks.  

 

Adam

 

Share this post


Link to post
Share on other sites

I get this error:

error: _GetObjectDaclIncludeInherit(): undefined function.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

@Valnurat  Sorry about that.  I forgot that some function were not in the original UDF.  The one ptrex linked is the one.  I updated the UDF to use Unicode.  That is the one I'm using.  Here is the link. 

 

Adam

 

Share this post


Link to post
Share on other sites

Thank you for your support.

But I'm sorry, I now get this message as attached.

PermError.PNG


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
On 5/18/2020 at 1:18 PM, water said:

I have written a skript to get the ACL listing and display the result in a TreeView.
It's about 10 years old, written in German and uses the old Excel UDF - so it definitely needs a brush up.
But if you are interested ...

@water - Yes, I would be interested.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
On 5/25/2020 at 8:13 AM, Valnurat said:

Thank you for your support.

But I'm sorry, I now get this message as attached.

PermError.PNG

@AdamUL - I'm sorry, but do you know why I get this error? I get error because I tried to use the "_GetObjectDacl"

If I tried to use the "_GetObjectDaclIncludeInherit", I get this error:

 

Capture.PNG


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
On 5/29/2020 at 9:27 AM, Valnurat said:

@water - Yes, I would be interested.

I had a look at my code archive and unfortunately I can't find the preparation code for my two-step approach:
First step retrieves a list of permissions for the selected path by running something like CACLS, processes the output and writes it to a file.
The second step displays the file in a TreeView and adds some additional features (search, export ...)

But without the code for step one this doesn't help much.

I did a Google search and found some (free) tools to display permissions: https://blog.netwrix.com/2017/08/18/top-5-free-tools-for-ntfs-permissions-reporting/
Maybe there is something that fits your needs?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-07-21 - Version 1.5.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...