Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7626809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:22:31+00:00 2026-05-31T05:22:31+00:00

I have a C# (Visual Studio 2010) application to manage objects in Microsoft Active

  • 0

I have a C# (Visual Studio 2010) application to manage objects in Microsoft Active Directory. When I want to move an organization unit in my application, the software tells me, that I have insufficient priviledges to do that. That’s because many objects in our directory are protected from accidental deletion.

Now I would like to check my application if an object is protected. If so, it should deactivate this protection, then move the object to another ou and finally set the protection again.

I’ve tried

// entry is a DirectoryEntry-Object
entry.Properties["ProtectedFromAccidentalDeletion"].Value = false;

but that gives me an exception.

In Microsoft Powershell you can do it that way:

Get-ADOrganizationalUnit -Filter 'Name -like "*"' | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true

Is it possible to realize this in C#, too?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:22:32+00:00Added an answer on May 31, 2026 at 5:22 am

    You need to add two entries to the ACL for the object:

    • Deny Everyone Delete
    • Deny Everyone Delete Tree

    I just dug up some really old code to do this that should work:

    Dim currentOU as DirectoryEntry ' This is the object you want to protect
    Dim deleteAce As New ActiveDirectoryAccessRule(New NTAccount("Everyone"), ActiveDirectoryRights.Delete, AccessControlType.Deny)
    Dim deleteSubtreeAce As New ActiveDirectoryAccessRule(New NTAccount("Everyone"), ActiveDirectoryRights.DeleteTree, AccessControlType.Deny)
    
    Dim currentACL As ActiveDirectorySecurity = currentOU.ObjectSecurity
    
    Dim deleteDeny As Boolean = False
    Dim deleteSubtreeDeny As Boolean = False
    
    For Each ace As ActiveDirectoryAccessRule In currentACL.GetAccessRules(True, False, GetType(NTAccount))
        If ace.IdentityReference.Value = "Everyone" Then
            If ace.ActiveDirectoryRights = ActiveDirectoryRights.Delete Then
                deleteDeny = True
            ElseIf ace.ActiveDirectoryRights = ActiveDirectoryRights.DeleteTree Then
                deleteSubtreeDeny = True
            End If
        End If
    Next
    
    If Not (deleteDeny AndAlso deleteSubtreeDeny) Then
        currentACL.AddAccessRule(deleteAce)
        currentACL.AddAccessRule(deleteSubtreeAce)
    
        currentOU.CommitChanges()
    
        Console.WriteLine("Protected: " & currentOU.Path)
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Visual Studio 2010 RC -> Silverlight Application We have a library of images that
I have installed Visual Studio 2010 RC. I want to install Visual C# 2008
I have download and installed Visual Studio 2010 RC and I want to develop
I have a Visual Studio 2010 Windows Forms application in which I start a
I have a Visual Studio 2010 MVC2 web application that I'm building via the
I have an asp.net web application (c#) in visual studio 2010 that is heavily
I have a web application solution existing under Visual Studio 2010. Part of this
I have a stackoverflow problem with a C# application written using Visual Studio 2010
I have several forms in a C# application. I use Visual Studio 2010 Beta,
I have Visual Studio 2010 beta 2 installed and Expression Blend Preview for .NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.