Skip to content

Instantly share code, notes, and snippets.

@SmugZombie
Created June 15, 2016 23:45
Show Gist options
  • Save SmugZombie/b3e11a5580a6b96727cdb3be3f98d6d6 to your computer and use it in GitHub Desktop.
Save SmugZombie/b3e11a5580a6b96727cdb3be3f98d6d6 to your computer and use it in GitHub Desktop.
;ComObjError(false)
;AccessMask: 2032127 = FULL | 1179817 = READ | 1179958 = WRITE | 1245631 = CHANGE
;Flags: 0 = This folder only | 1 = This folder and files | 2 = This folder and subfolders | 3 = This folder, subfolders and files
;Examples
SetSecurityRegister("HKLM\Software\Test", "S-1-1-0", "2032127")
SetSecurityFile("C:\Temp", "S-1-1-0", "1179817", "3")
ExitApp
SetSecurityRegister(RegKey, Trustee, AccessMask)
{
dacl := ComObjCreate("AccessControlList")
sd := ComObjCreate("SecurityDescriptor")
newAce := ComObjCreate("AccessControlEntry")
sdutil := ComObjCreate("ADsSecurityUtility")
sd := sdUtil.GetSecurityDescriptor(RegKey, 3, 1)
dacl := sd.DiscretionaryAcl
newAce.Trustee := Trustee
newAce.AccessMask := AccessMask
newAce.AceType := 0
dacl.AddAce(newAce)
sdutil.SetSecurityDescriptor(RegKey, 3, sd, 1)
Return A_LastError
}
SetSecurityFile(File, Trustee, AccessMask, Flags)
{
dacl := ComObjCreate("AccessControlList")
sd := ComObjCreate("SecurityDescriptor")
newAce := ComObjCreate("AccessControlEntry")
sdutil := ComObjCreate("ADsSecurityUtility")
sd := sdUtil.GetSecurityDescriptor(File, 1, 1)
dacl := sd.DiscretionaryAcl
newAce.Trustee := Trustee
newAce.AccessMask := AccessMask
newAce.AceFlags := Flags
newAce.AceType := 0
dacl.AddAce(newAce)
sdutil.SetSecurityDescriptor(File, 1, sd, 1)
Return A_LastError
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment