Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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)

public static IEnumerator PolicyHierarchy ()
public static IEnumerator PolicyHierarchy ()
public static function PolicyHierarchy () : IEnumerator
Not applicable.

Return Value

An IEnumerator for PolicyLevel objects that compose the security policy hierarchy.

Exception typeCondition

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.

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);
            }
        }
    }
}

private static void DeleteCustomCodeGroups()
{
    // Delete the custom code groups that were created.
    IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();
    while (policyEnumerator.MoveNext()) {
        PolicyLevel machineLevel = 
            ((PolicyLevel)(policyEnumerator.get_Current()));
        IList childCodeGroups = 
            machineLevel.get_RootCodeGroup().get_Children();
        IEnumerator childGroups = childCodeGroups.GetEnumerator();
        while (childGroups.MoveNext()) {
            CodeGroup thisCodeGroup = 
                ((CodeGroup)(childGroups.get_Current()));
            if (thisCodeGroup.get_Name().equalsIgnoreCase
                    ("MyCompanyCodeGroup")) {
                machineLevel.get_RootCodeGroup()
                    .RemoveChild(thisCodeGroup);
            }
        }
    }
} //DeleteCustomCodeGroups

  • SecurityPermission  for the ability to view and modify policy. Associated enumeration: SecurityPermissionFlag.ControlPolicy

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft