Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 PolicyHierarchy Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
SecurityManager..::.PolicyHierarchy Method

Provides an enumerator to access the security policy hierarchy by levels, such as computer policy and user policy.

Namespace:  System.Security
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public Shared Function PolicyHierarchy As IEnumerator
Visual Basic (Usage)
Dim returnValue As IEnumerator

returnValue = SecurityManager.PolicyHierarchy()
C#
public static IEnumerator PolicyHierarchy()
Visual C++
public:
static IEnumerator^ PolicyHierarchy()
JScript
public static function PolicyHierarchy() : IEnumerator

Return Value

Type: System.Collections..::.IEnumerator
An IEnumerator for PolicyLevel objects that compose the security policy hierarchy.
ExceptionCondition
SecurityException

The code that calls this method does not have SecurityPermissionFlag..::.ControlPolicy.

The returned enumerator provides successive PolicyLevel objects that represent the policy at the respective (machine, user, enterprise, application domain) level of the hierarchy. These objects are the live policy objects; altering these objects can have unpredictable results.

Minimum policy hierarchy consists of a machine level, an enterprise level, and a user level. However, the hierarchy can include additional levels.

For the complete example, see the SecurityManager class topic.

Visual Basic
Private Shared Sub DeleteCustomCodeGroups()
    ' Delete the custom code groups that were created.
    Dim policyEnumerator As IEnumerator = SecurityManager.PolicyHierarchy()
    While policyEnumerator.MoveNext()
        Dim machineLevel As PolicyLevel = CType(policyEnumerator.Current, PolicyLevel)
        Dim childCodeGroups As IList = machineLevel.RootCodeGroup.Children
        Dim childGroups As IEnumerator = childCodeGroups.GetEnumerator()
        While childGroups.MoveNext()
            Dim thisCodeGroup As CodeGroup = CType(childGroups.Current, CodeGroup)
            If thisCodeGroup.Name = "MyCompanyCodeGroup" Then
                machineLevel.RootCodeGroup.RemoveChild(thisCodeGroup)
            End If
        End While
    End While
End Sub 'DeleteCustomCodeGroups

C#
private static void DeleteCustomCodeGroups()
{
    // Delete the custom code groups that were created.
    IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();
    while(policyEnumerator.MoveNext())
    {
        PolicyLevel machineLevel = (PolicyLevel)policyEnumerator.Current;
        IList childCodeGroups = machineLevel.RootCodeGroup.Children;
        IEnumerator childGroups = childCodeGroups.GetEnumerator();
        while(childGroups.MoveNext())
        {
            CodeGroup thisCodeGroup = (CodeGroup)childGroups.Current;
            if( thisCodeGroup.Name == "MyCompanyCodeGroup")
            {
                machineLevel.RootCodeGroup.RemoveChild(thisCodeGroup);
            }
        }
    }
}
Visual C++
void DeleteCustomCodeGroups()
{
   // Delete the custom code groups that were created.
   IEnumerator^ policyEnumerator = SecurityManager::PolicyHierarchy();
   while ( policyEnumerator->MoveNext() )
   {
      PolicyLevel^ machineLevel = dynamic_cast<PolicyLevel^>(policyEnumerator->Current);
      IList^ childCodeGroups = machineLevel->RootCodeGroup->Children;
      IEnumerator^ childGroups = childCodeGroups->GetEnumerator();
      while ( childGroups->MoveNext() )
      {
         CodeGroup^ thisCodeGroup = dynamic_cast<CodeGroup^>(childGroups->Current);
         if ( thisCodeGroup->Name->Equals( "MyCompanyCodeGroup" ) )
         {
            machineLevel->RootCodeGroup->RemoveChild( thisCodeGroup );
         }
      }
   }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker