Page 1 of 1 1
Topic Options
#176183 - 2007-05-10 07:13 PM NTFSPerms.... Finally!
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
At long last, I've finally done it.
I have managed to set permissions on a folder without inheritance and the sorting order being screwed up. But before I submit a fullfledged UDF I'd like to ask you all to try this UDF on your networks/home environments and see how it works out with inheritance and sorting order.

XP is needed or Activeds.dll at least (comes standard in XP).

Things to test:
1. Add a new user (in the form of @LDOMAIN\@USERID or @WKSTA\@USERID) to a folder.
2. open the security TAB on the folder and see if it worked.
3. create a subfolder and check the security tab there.

If all 3 work without errors, or with errors I'd like to know about it.
Without any further ado here's the preliminary UDF:
 Code:
Function NTFSPerms($cmd,$object,Optional $trustee,Optional $perms)
  Dim $adsu, $sd, $dacl, $ace, $newace
  $adsu = CreateObject("ADsSecurityUtility")
  If @error Exit @error EndIf
  $sd = $adsu.GetSecurityDescriptor($object,1, 1)
  $dacl = $sd.DiscretionaryAcl
  Select
    Case $cmd = "Owner"
      ? $sd.Owner
    Case $cmd = "Count"
      ? $dacl.AceCount
    Case $cmd = "Show"
      For Each $Ace in $dacl
        ? $Ace.Trustee
        ? $Ace.AceFlags
        ? $Ace.AccessMask
        ? $Ace.AceType
        ? $Ace.Flags
        ?
      Next
    Case $cmd = "DEL"
      If $trustee <> ""
        For Each $ace In $Dacl
          If $ace.trustee = $trustee
            $Dacl.RemoveAce($Ace)
          EndIf
        Next
        $sd.DiscretionaryAcl = $Dacl
        $adsu.SetSecurityDescriptor($object,1,$sd,1)
      Else
        Exit 1
      EndIf
    Case $cmd = "ADD"
      If $trustee <> ""
        $NewAce = CreateObject("AccessControlEntry")
        $NewAce.Trustee = $trustee
        $NewAce.AceFlags = 3
        $NewAce.AccessMask = -1 ;2032127
        $NewAce.AceType = 0
        $dacl.AddAce($NewAce)
        $sd.DiscretionaryAcl = $Dacl
        $adsu.SetSecurityDescriptor($object,1,$sd,1)
        ? @serror
      Else
        Exit 1
      EndIf
    Case 1
      Exit 1
  EndSelect
EndFunction


Usage:
NTFSPerms("ADD","C:\testfolder","DOMAIN\user")
NTFSPerms("DEL","C:\testfolder","DOMAIN\user")
NTFSPerms("OWNER","D:\testfolder")
NTFSPerms("SHOW","D:\testfolder")
NTFSPerms("COUNT","D:\testfolder")

Top
#176186 - 2007-05-10 07:56 PM Re: NTFSPerms.... Finally! [Re: Arend_]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I haven't tried it yet, but I would suggest changing "SHOW" to "GET...". Maybe something like NTFSPerms("GETTrustee","D:\testfolder"), and NTFSPerms("GETAceFlags","D:\testfolder"), etc.

Maybe even add an option like "GetProperties" and return all the settings in an array or a comma separated string.

Top
#176196 - 2007-05-11 08:27 AM Re: NTFSPerms.... Finally! [Re: Allen]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
I will, in the final UDF, this is just a quick WIP one.
Thanks for the suggestion though \:\)

Top
#176385 - 2007-05-21 10:37 PM Re: NTFSPerms.... Finally! [Re: Arend_]
Peter Fry Offline
Getting the hang of it

Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
looks great i'll give it a whirl tomorrow in work

is there any way of setting the permissions like read / write / modify / full?

and to assign groups in stead of users?
i.e. add domain admins as full control and add domain users (or other group) to modify control?

looks great! can't wait to try this in work tomorrow

Top
#176386 - 2007-05-21 10:41 PM Re: NTFSPerms.... Finally! [Re: Peter Fry]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Read/Write/Modify is in the making, I'll add it in the next wip. Until then only FULL is available.

You can already assign groups just do it in the form of "DOMAINNAME\GROUPNAME"

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 533 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.056 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org