func init if(linked("RegistryKey")) // add using module sys.add_use('Microsoft.Win32') sys.add_use('System.Security.AccessControl') // defines an instance of RegistryKey and RegistrySecurity this.setfield('rk', d("RegistryKey")) if(linked("doSetAccessControl")) sys.add_object(this.codename, 'RegistrySecurity') sys.add_var('user', 'string') end // initialize properties if(linked("onError")) sys.add_use('System.Security') this.setfield('ex', 'ex' + this.id) end end end func doSetAccessControl(data) if(linked("RegistryKey")) linked("onError") ? blk.println('try {').inc() : '' if(linked("AccessControl")) if(not isdef("Inheritance")) a = this.props("Inheritance").value flg1 = ((a _and_ 1) ? '|InheritanceFlags.ContainerInherit' : '') + ((a _and_ 2) ? '|InheritanceFlags.ObjectInherit' : '') end if(not isdef("Propagation")) a = this.props("Propagation").value flg2 = ((a _and_ 1) ? '|PropagationFlags.NoPropagateInherit' : '') + ((a _and_ 2) ? '|PropagationFlags.InheritOnly' : '') end blk.println(this.user, ' = Environment.UserDomainName + "\\\\" + Environment.UserName;') .println(this.codename, '.AddAccessRule(new RegistryAccessRule(', this.user, ', RegistryRights.', this.props("RegistryRights").value, ', InheritanceFlags.None', flg1, ', PropagationFlags.None', flg2, ', AccessControlType.', this.props("AccessType").value, '));') .println(this.rk, '.SetAccessControl(', this.codename, ');') end if(linked("onError")) blk.dec().println('} catch(UnauthorizedAccessException ', this.ex, ') {').inc() event("onError", this.ex + '.Message') blk.dec().println('}') end end end func AccessControl if(linked("RegistryKey")) if(not isdef("AccessSections")) a = this.props("AccessSections").value flg = ((a _and_ 1) ? '|AccessControlSections.Audit' : '') + ((a _and_ 2) ? '|AccessControlSections.Access' : '') + ((a _and_ 4) ? '|AccessControlSections.Owner' : '') + ((a _and_ 8) ? '|AccessControlSections.Group' : '') + ((a _and_ 16) ? '|AccessControlSections.All' : '') end return(this.rk + '.GetAccessControl(AccessControlSections.None' + flg + ')') end end