How to fix .NET C# error: System.Security.AccessControl.PrivilegeNotHeldException: The process does not possess the ‘SeSecurityPrivilege’ privilege which is required for this operation.
If encountered the error “System.Security.AccessControl.PrivilegeNotHeldException: The process does not possess the ‘SeSecurityPrivilege’ privilege which is required for this operation.”, when calling GetAccesControl,
with “AccessControlSections.All”. After I changed this to “AccessControlSections.Access” the problem was resolved.
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine($”Start application”);
DirectoryInfo dirInfo = Directory.CreateDirectory(“\\SomeNetworkPath”);
DirectorySecurity dirSecurity = dirInfo.GetAccessControl(AccessControlSections.Access);
Console.WriteLine($”Wait for user to close the application”);
Console.ReadLine();
}
}
<
p style=”background: #1e1e1e”>}