FileSystemAuditRule Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the FileSystemAuditRule class.
Overloads
FileSystemAuditRule(IdentityReference, FileSystemRights, AuditFlags) |
Initializes a new instance of the FileSystemAuditRule class using a reference to a user account, a value that specifies the type of operation associated with the audit rule, and a value that specifies when to perform auditing. |
FileSystemAuditRule(String, FileSystemRights, AuditFlags) |
Initializes a new instance of the FileSystemAuditRule class using a user account name, a value that specifies the type of operation associated with the audit rule, and a value that specifies when to perform auditing. |
FileSystemAuditRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AuditFlags) |
Initializes a new instance of the FileSystemAuditRule class using the name of a reference to a user account, a value that specifies the type of operation associated with the audit rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies when to perform auditing. |
FileSystemAuditRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AuditFlags) |
Initializes a new instance of the FileSystemAuditRule class using the name of a user account, a value that specifies the type of operation associated with the audit rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies when to perform auditing. |
FileSystemAuditRule(IdentityReference, FileSystemRights, AuditFlags)
Initializes a new instance of the FileSystemAuditRule class using a reference to a user account, a value that specifies the type of operation associated with the audit rule, and a value that specifies when to perform auditing.
public:
FileSystemAuditRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AuditFlags flags);
public FileSystemAuditRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AuditFlags flags);
new System.Security.AccessControl.FileSystemAuditRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AuditFlags -> System.Security.AccessControl.FileSystemAuditRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, flags As AuditFlags)
Parameters
- identity
- IdentityReference
An IdentityReference object that encapsulates a reference to a user account.
- fileSystemRights
- FileSystemRights
One of the FileSystemRights values that specifies the type of operation associated with the audit rule.
- flags
- AuditFlags
One of the AuditFlags values that specifies when to perform auditing.
Exceptions
The identity
parameter is not an IdentityReference object.
The identity
parameter is null
.
An incorrect enumeration was passed to the flags
parameter.
-or-
The None value was passed to the flags
parameter.
Remarks
Use this constructor to create an audit rule that you can persist using the FileSecurity or DirectorySecurity class. Audit rules determine when and how actions performed on system objects, such as files and folders, are logged.
Applies to
FileSystemAuditRule(String, FileSystemRights, AuditFlags)
Initializes a new instance of the FileSystemAuditRule class using a user account name, a value that specifies the type of operation associated with the audit rule, and a value that specifies when to perform auditing.
public:
FileSystemAuditRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AuditFlags flags);
public FileSystemAuditRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AuditFlags flags);
new System.Security.AccessControl.FileSystemAuditRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AuditFlags -> System.Security.AccessControl.FileSystemAuditRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, flags As AuditFlags)
Parameters
- identity
- String
The name of a user account.
- fileSystemRights
- FileSystemRights
One of the FileSystemRights values that specifies the type of operation associated with the audit rule.
- flags
- AuditFlags
One of the AuditFlags values that specifies when to perform auditing.
Exceptions
An incorrect enumeration was passed to the flags
parameter.
-or-
The None value was passed to the flags
parameter.
Examples
The following code example uses the FileSystemAuditRule class to add and then remove an audit rule from a file. You must supply a valid user or group account to run this example.
using System;
using System.IO;
using System.Security.AccessControl;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
string FileName = "test.xml";
Console.WriteLine("Adding access control entry for " + FileName);
// Add the access control entry to the file.
AddFileAuditRule(FileName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AuditFlags.Failure);
Console.WriteLine("Removing access control entry from " + FileName);
// Remove the access control entry from the file.
RemoveFileAuditRule(FileName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AuditFlags.Failure);
Console.WriteLine("Done.");
}
catch (IOException e)
{
Console.WriteLine("Unable to open the file: " + e.Message);
}
catch (PrivilegeNotHeldException e)
{
Console.WriteLine("The current account does not have the correct privileges: " + e.Message);
}
Console.ReadLine();
}
// Adds an ACL entry on the specified file for the specified account.
public static void AddFileAuditRule(string FileName, string Account, FileSystemRights Rights, AuditFlags AuditRule)
{
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(FileName);
// Add the FileSystemAuditRule to the security settings.
fSecurity.AddAuditRule(new FileSystemAuditRule(Account,
Rights,
AuditRule));
// Set the new access settings.
File.SetAccessControl(FileName, fSecurity);
}
// Removes an ACL entry on the specified file for the specified account.
public static void RemoveFileAuditRule(string FileName, string Account, FileSystemRights Rights, AuditFlags AuditRule)
{
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(FileName);
// Add the FileSystemAuditRule to the security settings.
fSecurity.RemoveAuditRule(new FileSystemAuditRule(Account,
Rights,
AuditRule));
// Set the new access settings.
File.SetAccessControl(FileName, fSecurity);
}
}
}
Imports System.IO
Imports System.Security.AccessControl
Module FileExample
Sub Main()
Try
Dim FileName As String = "test.xml"
Console.WriteLine("Adding access control entry for " + FileName)
' Add the access control entry to the file.
AddFileAuditRule(FileName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AuditFlags.Failure)
Console.WriteLine("Removing access control entry from " + FileName)
' Remove the access control entry from the file.
RemoveFileAuditRule(FileName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AuditFlags.Failure)
Console.WriteLine("Done.")
Catch e As IOException
Console.WriteLine("Unable to open the file: " & e.Message)
Catch e As PrivilegeNotHeldException
Console.WriteLine("The current account does not have the correct privileges: " & e.Message)
End Try
Console.ReadLine()
End Sub
' Adds an ACL entry on the specified file for the specified account.
Sub AddFileAuditRule(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal AuditRule As AuditFlags)
' Get a FileSecurity object that represents the
' current security settings.
Dim fSecurity As FileSecurity = File.GetAccessControl(FileName)
' Add the FileSystemAuditRule to the security settings.
fSecurity.AddAuditRule(New FileSystemAuditRule(Account, Rights, AuditRule))
' Set the new access settings.
File.SetAccessControl(FileName, fSecurity)
End Sub
' Removes an ACL entry on the specified file for the specified account.
Sub RemoveFileAuditRule(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal AuditRule As AuditFlags)
' Get a FileSecurity object that represents the
' current security settings.
Dim fSecurity As FileSecurity = File.GetAccessControl(FileName)
' Add the FileSystemAuditRule to the security settings.
fSecurity.RemoveAuditRule(New FileSystemAuditRule(Account, Rights, AuditRule))
' Set the new access settings.
File.SetAccessControl(FileName, fSecurity)
End Sub
End Module
Remarks
Use this constructor to create an audit rule that you can persist using the FileSecurity or DirectorySecurity class. Audit rules determine when and how actions performed on system objects, such as files and folders, are logged.
The identity
parameter must identify a valid account on the current computer or domain. The string takes the following form, where DOMAIN
is the name of a valid domain or computer name and account
is the name of a valid user account on a domain or computer: DOMAIN\account
.
Applies to
FileSystemAuditRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AuditFlags)
Initializes a new instance of the FileSystemAuditRule class using the name of a reference to a user account, a value that specifies the type of operation associated with the audit rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies when to perform auditing.
public:
FileSystemAuditRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AuditFlags flags);
public FileSystemAuditRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AuditFlags flags);
new System.Security.AccessControl.FileSystemAuditRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AuditFlags -> System.Security.AccessControl.FileSystemAuditRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, flags As AuditFlags)
Parameters
- identity
- IdentityReference
An IdentityReference object that encapsulates a reference to a user account.
- fileSystemRights
- FileSystemRights
One of the FileSystemRights values that specifies the type of operation associated with the audit rule.
- inheritanceFlags
- InheritanceFlags
One of the InheritanceFlags values that specifies how access masks are propagated to child objects.
- propagationFlags
- PropagationFlags
One of the PropagationFlags values that specifies how Access Control Entries (ACEs) are propagated to child objects.
- flags
- AuditFlags
One of the AuditFlags values that specifies when to perform auditing.
Exceptions
The identity
parameter is not an IdentityReference object.
The identity
parameter is null
.
An incorrect enumeration was passed to the flags
parameter.
-or-
The None value was passed to the flags
parameter.
Remarks
Use this constructor to create an audit rule that you can persist using the FileSecurity or DirectorySecurity class. Audit rules determine when and how actions performed on system objects, such as files and folders, are logged.
Applies to
FileSystemAuditRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AuditFlags)
Initializes a new instance of the FileSystemAuditRule class using the name of a user account, a value that specifies the type of operation associated with the audit rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies when to perform auditing.
public:
FileSystemAuditRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AuditFlags flags);
public FileSystemAuditRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AuditFlags flags);
new System.Security.AccessControl.FileSystemAuditRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AuditFlags -> System.Security.AccessControl.FileSystemAuditRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, flags As AuditFlags)
Parameters
- identity
- String
The name of a user account.
- fileSystemRights
- FileSystemRights
One of the FileSystemRights values that specifies the type of operation associated with the audit rule.
- inheritanceFlags
- InheritanceFlags
One of the InheritanceFlags values that specifies how access masks are propagated to child objects.
- propagationFlags
- PropagationFlags
One of the PropagationFlags values that specifies how Access Control Entries (ACEs) are propagated to child objects.
- flags
- AuditFlags
One of the AuditFlags values that specifies when to perform auditing.
Remarks
Use this constructor to create an audit rule that you can persist using the FileSecurity or DirectorySecurity class. Audit rules determine when and how actions performed on system objects, such as files and folders, are logged.
The identity
parameter must identify a valid account on the current computer or domain. The string takes the following form, where DOMAIN
is the name of a valid domain or computer name and account
is the name of a valid user account on a domain or computer: DOMAIN\account
.