c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -


i trying set "applies to" field under folder auditing options programatically. in msdn, the code example there uses filesystemauditrule class add new audit rule folder. there nothing obvious in class set particular audit rule needs applied to.

this code using set permissions:

const string myfolder = @"s:\temp\somefoldertoaudit";  var account = new securityidentifier(wellknownsidtype.worldsid, null).translate(typeof(ntaccount));  filesecurity fsecurity = file.getaccesscontrol(myfolder, accesscontrolsections.audit);  fsecurity.addauditrule(new filesystemauditrule(account, filesystemrights.writedata | filesystemrights.delete | filesystemrights.changepermissions, auditflags.success));  file.setaccesscontrol(myfolder, fsecurity); 

this creates audit rules nicely except highlighted option below: applies option not being set

i need "this folder, subfolders , files" example or other "this folder only". don't want traverse directories , files , set same auditing rules on them. don't want try , manage inheritance either, rules protected that. need way set option preferably using managed code (p/invokes welcome if way).

thanks in advance assistance.

after bit of fiddling around managed find out how set "applies to" field. need use combination of inheritanceflags , propagationflags when creating audit rule object.

here example code (based on question example) shows combinations of flags , outcomes "applies to" field:

// folder (default) fsecurity.addauditrule(new filesystemauditrule(account, filesystemrights.writedata | filesystemrights.delete | filesystemrights.changepermissions, inheritanceflags.none, propagationflags.none, auditflags.success)); // folder , subfolders fsecurity.addauditrule(new filesystemauditrule(account, filesystemrights.writedata | filesystemrights.delete | filesystemrights.changepermissions, inheritanceflags.containerinherit, propagationflags.none, auditflags.success)); // folder , files fsecurity.addauditrule(new filesystemauditrule(account, filesystemrights.writedata | filesystemrights.delete | filesystemrights.changepermissions, inheritanceflags.objectinherit, propagationflags.none, auditflags.success)); // folder, subfolders , files fsecurity.addauditrule(new filesystemauditrule(account, filesystemrights.writedata | filesystemrights.delete | filesystemrights.changepermissions, inheritanceflags.containerinherit | inheritanceflags.objectinherit, propagationflags.none, auditflags.success)); // subfolders fsecurity.addauditrule(new filesystemauditrule(account, filesystemrights.writedata | filesystemrights.delete | filesystemrights.changepermissions, inheritanceflags.containerinherit, propagationflags.inheritonly, auditflags.success)); // files fsecurity.addauditrule(new filesystemauditrule(account, filesystemrights.writedata | filesystemrights.delete | filesystemrights.changepermissions, inheritanceflags.objectinherit, propagationflags.inheritonly, auditflags.success)); // subfolders , files fsecurity.addauditrule(new filesystemauditrule(account, filesystemrights.writedata | filesystemrights.delete | filesystemrights.changepermissions, inheritanceflags.containerinherit | inheritanceflags.objectinherit, propagationflags.inheritonly, auditflags.success)); 

this information , more on access control can found on this useful page michael taylor.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -