次の方法で共有


UIPermission クラス

ユーザー インターフェイスとクリップボードに関連するアクセス許可を制御します。このクラスは継承できません。

この型のすべてのメンバの一覧については、UIPermission メンバ を参照してください。

System.Object
   System.Security.CodeAccessPermission
      System.Security.Permissions.UIPermission

<Serializable>
NotInheritable Public Class UIPermission   Inherits CodeAccessPermission   Implements IUnrestrictedPermission
[C#]
[Serializable]
public sealed class UIPermission : CodeAccessPermission,   IUnrestrictedPermission
[C++]
[Serializable]
public __gc __sealed class UIPermission : public   CodeAccessPermission, IUnrestrictedPermission
[JScript]
public
   Serializable
class UIPermission extends CodeAccessPermission implements   IUnrestrictedPermission

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

ウィンドウでの描画およびユーザー入力イベントは、ユーザー インターフェイスです。

ウィンドウを使用するためのアクセス許可は、"無制限"、" SafeTopLevelWindows に制限"、" SafeSubWindows だけ"、または "ウィンドウでの描画やユーザー入力イベントによるアクセス不可"のいずれかになります。 SafeTopLevelWindows および SafeSubWindows では、有害なコードによるなりすまし攻撃を防ぐために、タイトルとサイズが制限されます。

クリップボードを使用するためのアクセス許可は、無制限、書き込み専用、またはクリップボードへのアクセス不可のいずれかです。貼り付けを制限すると、不正の可能性があるアプリケーションによって、ユーザーの同意なしにクリップボードからデータが取得されるのを防ぐことができます。ただし、ユーザーがキーボード コマンドを使用して切り取り、コピー、貼り付けの各操作を開始した場合、それらの操作は制限されません。

使用例

 
' This sample demonstrates the IsSubsetOf, Union, Intersect, Copy, ToXml and FromXml methods 
' of the UIPermission class.
Imports System
Imports System.Security
Imports System.Security.Permissions
Imports Microsoft.VisualBasic

<Assembly: CLSCompliant(True)> 

Public Class UIPermissionDemo

    ' The IsSubsetOf method determines whether the current permission is a subset of the specified permission.
    ' This demo uses the IsSubsetOf method to determine the relationship of two 
    ' UIPermissionWindow permissions and two UIPermissionClipboard permissions.
    Private Function IsSubsetOfWindowAndClipboardDemo() As Boolean
        Dim returnValue As Boolean = True
        Dim ui1, ui2 As UIPermissionWindow
        Dim cb1, cb2 As UIPermissionClipboard
        Dim uiIdPerm1, uiIdPerm2 As UIPermission
        Dim uiGen1 As New UIGenerator()
        Dim uiGen2 As New UIGenerator()
        uiGen1.ResetIndex()
        While uiGen1.CreateUI(uiIdPerm1, ui1, cb1)
            If uiIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            uiGen2.ResetIndex()
            Console.WriteLine("********************************************************" & ControlChars.Lf)

            While uiGen2.CreateUI(uiIdPerm2, ui2, cb2)
                If uiIdPerm2 Is Nothing Then
                    GoTo ContinueWhile2
                End If
                Try
                    If uiIdPerm1.IsSubsetOf(uiIdPerm2) Then
                        Console.WriteLine(uiIdPerm1.Window.ToString() & " and " _
                        & uiIdPerm1.Clipboard.ToString() & " is a subset of " _
                        & uiIdPerm2.Window.ToString() & "  and  " & uiIdPerm2.Clipboard.ToString())
                    Else
                        Console.WriteLine(uiIdPerm1.Window.ToString() & " and " _
                        & uiIdPerm1.Clipboard.ToString() & " is not a subset of " _
                        & uiIdPerm2.Window.ToString() & " and " & uiIdPerm2.Clipboard)
                    End If
                Catch e As Exception
                    Console.WriteLine("An exception was thrown  for subset :" & uiIdPerm1.ToString() _
                    & ControlChars.Lf & uiIdPerm2.ToString() & ControlChars.Lf & e.ToString())
                    returnValue = False
                End Try
ContinueWhile2:
            End While
ContinueWhile1:
        End While
        Return returnValue
    End Function 'IsSubsetOfWindowAndClipboardDemo

    ' Compare two UIPemissionWindow permissions.
    Private Function IsSubsetOfWindowDemo() As Boolean
        Dim returnValue As Boolean = True
        Dim ui1, ui2 As UIPermissionWindow
        Dim uiIdPerm1, uiIdPerm2 As UIPermission
        Dim uiGen1 As New UIGenerator()
        Dim uiGen2 As New UIGenerator()
        uiGen1.ResetIndex()
        While uiGen1.CreateUI(uiIdPerm1, ui1)
            If uiIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            uiGen2.ResetIndex()
            Console.WriteLine("********************************************************" & ControlChars.Lf)

            While uiGen2.CreateUI(uiIdPerm2, ui2)
                If uiIdPerm2 Is Nothing Then
                    GoTo ContinueWhile2
                End If
                Try
                    If uiIdPerm1.IsSubsetOf(uiIdPerm2) Then
                        Console.WriteLine(uiIdPerm1.Window.ToString() & " is a subset of " _
                        & uiIdPerm2.Window.ToString())
                    Else
                        Console.WriteLine(uiIdPerm1.Window.ToString() & " is not a subset of " _
                        & uiIdPerm2.Window.ToString())
                    End If
                Catch e As Exception
                    Console.WriteLine(("An exception was thrown  for subset :" & uiIdPerm1.ToString() _
                    & ControlChars.Lf & uiIdPerm2.ToString() & ControlChars.Lf & e.ToString()))
                    returnValue = False
                End Try
ContinueWhile2:
            End While
ContinueWhile1:
        End While
        Return returnValue
    End Function 'IsSubsetOfWindowDemo

    ' Compare two UIPermissionClipboard permissions.
    Private Function IsSubsetOfClipboardDemo() As Boolean
        Dim returnValue As Boolean = True
        Dim cb1, cb2 As UIPermissionClipboard
        Dim uiIdPerm1, uiIdPerm2 As UIPermission
        Dim uiGen1 As New UIGenerator()
        Dim uiGen2 As New UIGenerator()
        uiGen1.ResetIndex()
        While uiGen1.CreateUI(uiIdPerm1, cb1)
            If uiIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            uiGen2.ResetIndex()
            Console.WriteLine("********************************************************" & ControlChars.Lf)

            While uiGen2.CreateUI(uiIdPerm2, cb2)
                If uiIdPerm2 Is Nothing Then
                    GoTo ContinueWhile2
                End If
                Try
                    If uiIdPerm1.IsSubsetOf(uiIdPerm2) Then
                        Console.WriteLine(uiIdPerm1.Clipboard.ToString() & " is a subset of " _
                        & uiIdPerm2.Clipboard.ToString())
                    Else
                        Console.WriteLine(uiIdPerm1.Clipboard.ToString() & " is not a subset of " _
                        & uiIdPerm2.Clipboard.ToString())
                    End If
                Catch e As Exception
                    Console.WriteLine("An exception was thrown  for subset :" _
                    & uiIdPerm1.ToString() & ControlChars.Lf & uiIdPerm2.ToString() _
                    & ControlChars.Lf & e.ToString())
                    returnValue = False
                End Try
ContinueWhile2:
            End While
ContinueWhile1:
        End While
        Return returnValue
    End Function 'IsSubsetOfClipboardDemo

    ' Union creates a new permission that is the union of the current permission and the specified permission.
    Private Function UnionDemo() As Boolean
        Dim returnValue As Boolean = True
        Dim ui1, ui2 As UIPermissionWindow
        Dim cb1, cb2 As UIPermissionClipboard
        Dim uiIdPerm1, uiIdPerm2 As UIPermission
        Dim uiIdPerm3 As IPermission
        Dim uiGen1 As New UIGenerator()
        Dim uiGen2 As New UIGenerator()
        uiGen1.ResetIndex()
        While uiGen1.CreateUI(uiIdPerm1, ui1, cb1)
            If uiIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            Console.WriteLine("**********************************************************" & ControlChars.Lf)
            uiGen2.ResetIndex()

            While uiGen2.CreateUI(uiIdPerm2, ui2, cb2)
                If uiIdPerm2 Is Nothing Then
                    GoTo ContinueWhile2
                End If
                uiIdPerm3 = CType(uiIdPerm1.Union(uiIdPerm2), UIPermission)
                uiIdPerm3 = uiIdPerm1.Union(uiIdPerm2)

                If uiIdPerm3 Is Nothing Then
                    Console.WriteLine(("The union of " & ui1.ToString() & " and " & ui2.ToString() & " is null."))
                Else
                    Console.WriteLine(("The union of " & uiIdPerm1.Window.ToString() & " and " _
                    & uiIdPerm1.Clipboard.ToString() & " with " & uiIdPerm2.Window.ToString() _
                    & " and " & uiIdPerm2.Clipboard.ToString() & " = " & ControlChars.Lf _
                    & ControlChars.Tab & CType(uiIdPerm3, UIPermission).Window.ToString() & " and " _
                    & CType(uiIdPerm3, UIPermission).Clipboard.ToString()))
                End If
ContinueWhile2:
            End While
ContinueWhile1:
        End While


        Return returnValue
    End Function 'UnionDemo

    ' Intersect creates and returns a new permission that is the intersection of the current 
    ' permission and the permission specified.
    Private Function IntersectDemo() As Boolean
        Dim returnValue As Boolean = True
        Dim ui1, ui2 As UIPermissionWindow
        Dim cb1, cb2 As UIPermissionClipboard
        Dim uiIdPerm1, uiIdPerm2, uiIdPerm3 As UIPermission
        Dim uiGen1 As New UIGenerator()
        Dim uiGen2 As New UIGenerator()
        uiGen1.ResetIndex()
        While uiGen1.CreateUI(uiIdPerm1, ui1, cb1)
            If uiIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            Console.WriteLine("**********************************************************" & ControlChars.Lf)
            uiGen2.ResetIndex()

            While uiGen2.CreateUI(uiIdPerm2, ui2, cb2)
                If uiIdPerm2 Is Nothing Then
                    GoTo ContinueWhile2
                End If
                uiIdPerm3 = CType(uiIdPerm1.Intersect(uiIdPerm2), UIPermission)
                If Not (uiIdPerm3 Is Nothing) Then
                    Console.WriteLine(("The intersection of " & uiIdPerm1.Window.ToString() & " and " _
                    & uiIdPerm1.Clipboard.ToString() & " with " & uiIdPerm2.Window.ToString() _
                    & " and " & uiIdPerm2.Clipboard.ToString() & " = " & ControlChars.Lf _
                    & ControlChars.Tab & CType(uiIdPerm3, UIPermission).Window.ToString() & " and " _
                    & CType(uiIdPerm3, UIPermission).Clipboard.ToString()))
                Else
                    Console.WriteLine(("The intersection of " & ui1.ToString() & " and " & cb1.ToString() _
                    & " with " & ui2.ToString() & " and " & cb2.ToString() & " is null."))
                End If
ContinueWhile2:
            End While
ContinueWhile1:
        End While

        Return returnValue
    End Function 'IntersectDemo

    'Copy creates and returns an identical copy of the current permission.
    Private Function CopyDemo() As Boolean
        Dim returnValue As Boolean = True

        Dim ui1 As UIPermissionWindow
        Dim cb1 As UIPermissionClipboard
        Dim uiIdPerm1, uiIdPerm2 As UIPermission

        Dim uiGen1 As New UIGenerator()
        Dim uiGen2 As New UIGenerator()

        uiGen1.ResetIndex()
        While uiGen1.CreateUI(uiIdPerm1, ui1, cb1)
            If uiIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            uiGen2.ResetIndex()
            Console.WriteLine("********************************************************" & ControlChars.Lf)
            Try
                uiIdPerm2 = CType(uiIdPerm1.Copy(), UIPermission)
                Console.WriteLine(("Result of copy = " & uiIdPerm2.ToString()))

            Catch e As Exception
                Console.WriteLine(("The copy failed :" & uiIdPerm1.ToString() & e.ToString()))
                GoTo ContinueWhile1
            End Try
ContinueWhile1:
        End While
        Return returnValue
    End Function 'CopyDemo

    ' ToXml creates an XML encoding of the permission and its current state; 
    ' FromXml reconstructs a permission with the specified state from the XML encoding. 
    Private Function ToFromXmlDemo() As Boolean
        Dim returnValue As Boolean = True

        Dim ui1 As UIPermissionWindow
        Dim cb1 As UIPermissionClipboard
        Dim uiIdPerm1, uiIdPerm2 As UIPermission
        Dim uiGen1 As New UIGenerator()
        Dim uiGen2 As New UIGenerator()
        uiGen1.ResetIndex()
        While uiGen1.CreateUI(uiIdPerm1, ui1, cb1)
            If uiIdPerm1 Is Nothing Then
                GoTo ContinueWhile1
            End If
            Console.WriteLine("********************************************************" & ControlChars.Lf)
            uiGen2.ResetIndex()
            Try
                uiIdPerm2 = New UIPermission(PermissionState.None)
                uiIdPerm2.FromXml(uiIdPerm1.ToXml())
                Console.WriteLine(("Result of ToFromXml = " & uiIdPerm2.ToString()))

            Catch e As Exception
                Console.WriteLine(("ToFromXml failed :" & uiIdPerm1.ToString() & e.ToString()))
                GoTo ContinueWhile1
            End Try
ContinueWhile1:
        End While

        Return returnValue
    End Function 'ToFromXmlDemo

    ' Invoke all demos.
    Public Function runDemo() As Boolean
        Dim returnCode As Boolean = True
        Dim tempReturnCode As Boolean

        ' Call the IsSubsetOfClipboard demo.
        tempReturnCode = IsSubsetOfClipboardDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("IsSubsetOfClipboard demo completed successfully.")
        Else
            Console.Out.WriteLine("IsSubsetOfClipboard demo failed")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the IsSubsetOfWindow demo.
        tempReturnCode = IsSubsetOfWindowDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("IsSubsetOfWindow demo completed successfully.")
        Else
            Console.Out.WriteLine("IsSubsetOfWindow demo failed")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the IsSubsetOfWindowAndClipboard demo.
        tempReturnCode = IsSubsetOfWindowAndClipboardDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("IsSubsetOfWindowAndClipboard demo completed successfully.")
        Else
            Console.Out.WriteLine("IsSubsetOfWindowAndClipboard demo failed")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the Union demo.
        tempReturnCode = UnionDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("Union demo completed successfully.")
        Else
            Console.Out.WriteLine("Union demo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the Intersect demo.    
        tempReturnCode = IntersectDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("Intersect demo completed successfully. ")
        Else
            Console.Out.WriteLine("Intersect demo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode


        ' Call the Copy demo.    
        tempReturnCode = CopyDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("Copy demo completed successfully.")
        Else
            Console.Out.WriteLine("Copy demo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the ToFromXml demo.    
        tempReturnCode = ToFromXmlDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("ToFromXml demo completed successfully.")
        Else
            Console.Out.WriteLine("ToFromXml demo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        Return returnCode
    End Function 'runDemo

    ' Test harness.
    Public Overloads Shared Sub Main(ByVal args() As [String])
        Try
            Dim democase As New UIPermissionDemo()
            Dim returnCode As Boolean = democase.runDemo()
            If returnCode Then
                Console.Out.WriteLine("UIPermission demo completed successfully.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 100
            Else
                Console.Out.WriteLine("UIPermission demo failed.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 101
            End If
        Catch e As Exception
            Console.Out.WriteLine("UIPermission demo failed")
            Console.WriteLine(e.ToString())
            Console.Out.WriteLine("Press the Enter key to exit.")
            Dim consoleInput As String = Console.ReadLine()
            System.Environment.ExitCode = 101
        End Try
    End Sub 'Main
End Class 'UIPermissionDemo


' This class generates UIPermission objects.

Friend Class UIGenerator
    Private myUI As UIPermissionWindow() = {UIPermissionWindow.AllWindows, UIPermissionWindow.SafeSubWindows, UIPermissionWindow.SafeTopLevelWindows, UIPermissionWindow.NoWindows}
    Private myCB As UIPermissionClipboard() = {UIPermissionClipboard.AllClipboard, UIPermissionClipboard.OwnClipboard, UIPermissionClipboard.NoClipboard}

    Private uiIndex As Integer = 0
    Private cbIndex As Integer = 0


    Public Sub New()
        ResetIndex()
    End Sub 'New


    Public Sub ResetIndex()
        uiIndex = 0
        cbIndex = 0
    End Sub 'ResetIndex

    Public Sub ResetUIIndex()
        uiIndex = 0
    End Sub 'ResetUIIndex

    ' Create a UIPermission object using both a UIPermission Window enumeration and a 
    ' UIPermissionClipboard enumeration to specify permissions.
    Public Overloads Function CreateUI(ByRef UIPerm As UIPermission, ByRef ui As UIPermissionWindow, ByRef cb As UIPermissionClipboard) As Boolean

        If uiIndex >= myUI.Length AndAlso cbIndex >= myCB.Length - 1 Then
            ui = UIPermissionWindow.NoWindows
            cb = UIPermissionClipboard.NoClipboard
            UIPerm = New UIPermission(ui, cb)
            Return False
        End If

        If uiIndex >= myUI.Length AndAlso cbIndex < myCB.Length - 1 Then
            ResetUIIndex()
            ui = myUI(uiIndex)
            uiIndex = uiIndex + 1
            cbIndex = cbIndex + 1
            cb = myCB(cbIndex)
            'ToDo: Unsupported operator
            'ToDo: && operator not supported within expressions
            UIPerm = New UIPermission(ui, cb)
            Return True
        End If

        ui = myUI(uiIndex)
        uiIndex = uiIndex + 1
        cb = myCB(cbIndex)
        Try
            UIPerm = New UIPermission(ui, cb)
            Return True
        Catch e As Exception
            Console.WriteLine(("Cannot create UIPermission: " & ui & " " & e.ToString()))
            UIPerm = New UIPermission(PermissionState.None)
            ui = UIPermissionWindow.NoWindows
            Return True
        End Try
    End Function 'CreateUI

    ' Create a UIPermission using the specified UIPermissionWindow enumeration 
    ' to set Window permissions.
    Public Overloads Function CreateUI(ByRef uiPerm As UIPermission, _
    ByRef ui As UIPermissionWindow) As Boolean

        If uiIndex >= myUI.Length Then
            uiPerm = New UIPermission(PermissionState.None)
            ui = UIPermissionWindow.NoWindows
            Return False
        End If
        ui = myUI(uiIndex)
        uiIndex = uiIndex + 1
        Try
            uiPerm = New UIPermission(ui)
            Return True
        Catch e As Exception
            Console.WriteLine(("Cannot create UIPermission: " & ui & " " & e.ToString()))
            uiPerm = New UIPermission(PermissionState.None)
            ui = UIPermissionWindow.NoWindows
            Return True
        End Try
    End Function 'CreateUI

    ' Create a UIPermission using  Create a UIPermission using the specified UIPermissionClipboard enumeration to set Clipboard permissions.
    Public Overloads Function CreateUI(ByRef uiPerm As UIPermission, ByRef cb As UIPermissionClipboard) As Boolean


        If cbIndex >= myCB.Length Then
            uiPerm = New UIPermission(PermissionState.None)
            cb = UIPermissionClipboard.NoClipboard

            Return False
        End If


        cb = myCB(cbIndex)
        cbIndex = cbIndex + 1
        Try
            uiPerm = New UIPermission(cb)
            Return True
        Catch e As Exception
            Console.WriteLine(("Cannot create UIPermission: " & cb & " " & e.ToString()))
            uiPerm = New UIPermission(PermissionState.None)
            cb = UIPermissionClipboard.NoClipboard
            Return True
        End Try
    End Function 'CreateUI
'End of UIGenerator.

[C#] 
// This sample demonstrates the IsSubsetOf, Union, Intersect, Copy, ToXml and FromXml methods 
// of the UIPermission class.

using System;
using System.Security; 
using System.Security.Permissions; 

[assembly:CLSCompliant(true)]

public class UIPermissionDemo
{
// The IsSubsetOf method determines whether the current permission is a subset of the specified permission.
// This demo uses the IsSubsetOf method to determine the relationship of two 
// UIPermissionWindow permissions and two UIPermissionClipboard permissions.
    private bool IsSubsetOfWindowAndClipboardDemo()
    {
        bool returnValue = true;
        UIPermissionWindow ui1,ui2;
        UIPermissionClipboard cb1, cb2;
        UIPermission uiIdPerm1,uiIdPerm2;
        UIGenerator uiGen1 = new UIGenerator();
        UIGenerator uiGen2 = new UIGenerator();
        uiGen1.ResetIndex();
        while(uiGen1.CreateUI(out uiIdPerm1, out ui1, out cb1)) 
        {
            if(uiIdPerm1 == null) continue;
            uiGen2.ResetIndex();
            Console.WriteLine("********************************************************\n");

            while(uiGen2.CreateUI(out uiIdPerm2, out ui2, out cb2)) 
            {
                if(uiIdPerm2 == null) continue;
                try
                {            
                    if (uiIdPerm1.IsSubsetOf(uiIdPerm2))
                    {
                        Console.WriteLine(uiIdPerm1.Window + " and " + uiIdPerm1.Clipboard + " is a subset of " + 
                            uiIdPerm2.Window  +  "  and  " + uiIdPerm2.Clipboard);
                    }
                    else
                    {
                        Console.WriteLine(uiIdPerm1.Window + " and " + uiIdPerm1.Clipboard + " is not a subset of " + 
                            uiIdPerm2.Window  +  " and " + uiIdPerm2.Clipboard);
                    }
                }
                catch(Exception e) 
                {
                    Console.WriteLine("An exception was thrown  for subset :" + uiIdPerm1 + "\n" + 
                        uiIdPerm2 +"\n" + e);
                    returnValue=false;
                }
            }
        }
        return returnValue;
    }
// Compare two UIPemissionWindow permissions.
    private bool IsSubsetOfWindowDemo()
    {
        bool returnValue = true;
        UIPermissionWindow ui1,ui2;
        UIPermission uiIdPerm1,uiIdPerm2;
        UIGenerator uiGen1 = new UIGenerator();
        UIGenerator uiGen2 = new UIGenerator();
        uiGen1.ResetIndex();
        while(uiGen1.CreateUI(out uiIdPerm1, out ui1)) 
        {
            if(uiIdPerm1 == null) continue;
            uiGen2.ResetIndex();
            Console.WriteLine("********************************************************\n");

            while(uiGen2.CreateUI(out uiIdPerm2, out ui2)) 
            {
                if(uiIdPerm2 == null) continue;
                try
                {            
                    if (uiIdPerm1.IsSubsetOf(uiIdPerm2))
                    {
                        Console.WriteLine(uiIdPerm1.Window + " is a subset of " + uiIdPerm2.Window );
                    }
                    else
                    {
                        Console.WriteLine(uiIdPerm1.Window + " is not a subset of " + uiIdPerm2.Window);
                    }
                }
                catch(Exception e) 
                {
                    Console.WriteLine("An exception was thrown  for subset :" + uiIdPerm1 + "\n" + 
                        uiIdPerm2 +"\n" + e);
                    returnValue=false;
                }
            }
        }
        return returnValue;
    }
// Compare two UIPermissionClipboard permissions.
    private bool IsSubsetOfClipboardDemo()
    {
        bool returnValue = true;
        UIPermissionClipboard cb1, cb2;
        UIPermission uiIdPerm1,uiIdPerm2;
        UIGenerator uiGen1 = new UIGenerator();
        UIGenerator uiGen2 = new UIGenerator();
        uiGen1.ResetIndex();
        while(uiGen1.CreateUI(out uiIdPerm1, out cb1)) 
        {
            if(uiIdPerm1 == null) continue;
            uiGen2.ResetIndex();
            Console.WriteLine("********************************************************\n");

            while(uiGen2.CreateUI(out uiIdPerm2, out cb2)) 
            {
                if(uiIdPerm2 == null) continue;
                try
                {            
                    if (uiIdPerm1.IsSubsetOf(uiIdPerm2))
                    {
                        Console.WriteLine(uiIdPerm1.Clipboard + " is a subset of " + uiIdPerm2.Clipboard);
                    }
                    else
                    {
                        Console.WriteLine(uiIdPerm1.Clipboard + " is not a subset of " + uiIdPerm2.Clipboard);
                    }
                }
                catch(Exception e) 
                {
                    Console.WriteLine("An exception was thrown  for subset :" + uiIdPerm1 + "\n" + 
                        uiIdPerm2 +"\n" + e);
                    returnValue=false;
                }
            }
        }
        return returnValue;
    }
// Union creates a new permission that is the union of the current permission and the specified permission.
    private bool UnionDemo()
    {
        bool returnValue = true;
        UIPermissionWindow ui1,ui2;
        UIPermissionClipboard cb1, cb2;
        UIPermission uiIdPerm1,uiIdPerm2;
        IPermission uiIdPerm3;
        UIGenerator uiGen1 = new UIGenerator();
        UIGenerator uiGen2 = new UIGenerator();
        uiGen1.ResetIndex();
        while(uiGen1.CreateUI(out uiIdPerm1, out ui1, out cb1)) 
        {
            if(uiIdPerm1 == null) continue;
            Console.WriteLine("**********************************************************\n");
            uiGen2.ResetIndex();

            while(uiGen2.CreateUI(out uiIdPerm2, out ui2, out cb2)) 
            {
                if(uiIdPerm2 == null) continue;
                uiIdPerm3 = (UIPermission)uiIdPerm1.Union(uiIdPerm2);
                uiIdPerm3 = uiIdPerm1.Union(uiIdPerm2);

                if(uiIdPerm3 == null)  
                {
                    Console.WriteLine("The union of " +  ui1 + " and " + ui2 + " is null." );
                }
                else
                {
                    Console.WriteLine("The union of " + uiIdPerm1.Window + " and " + uiIdPerm1.Clipboard + " with " + 
                        uiIdPerm2.Window + " and " + uiIdPerm2.Clipboard + " = \n\t" + 
                        ((UIPermission)uiIdPerm3).Window.ToString() + " and " + ((UIPermission)uiIdPerm3).Clipboard.ToString());
                }

            }
        }

        return returnValue;

    }
// Intersect creates and returns a new permission that is the intersection of the current 
// permission and the permission specified.
    private bool IntersectDemo()
    {
        bool returnValue = true;
        UIPermissionWindow ui1,ui2;
        UIPermissionClipboard cb1, cb2;
        UIPermission uiIdPerm1,uiIdPerm2,uiIdPerm3;
        UIGenerator uiGen1 = new UIGenerator();
        UIGenerator uiGen2 = new UIGenerator();
        uiGen1.ResetIndex();
        while(uiGen1.CreateUI(out uiIdPerm1, out ui1, out cb1)) 
        {
            if(uiIdPerm1 == null) continue;
            Console.WriteLine("**********************************************************\n");
            uiGen2.ResetIndex();

            while(uiGen2.CreateUI(out uiIdPerm2, out ui2, out cb2)) 
            {
                if(uiIdPerm2 == null) continue;
                uiIdPerm3 = (UIPermission)uiIdPerm1.Intersect(uiIdPerm2);
                if (uiIdPerm3 != null)
                {
                    Console.WriteLine("The intersection of " + uiIdPerm1.Window + " and " + uiIdPerm1.Clipboard + " with " + 
                        uiIdPerm2.Window + " and " + uiIdPerm2.Clipboard + " = \n\t" + 
                        ((UIPermission)uiIdPerm3).Window.ToString() + " and " + ((UIPermission)uiIdPerm3).Clipboard.ToString());
                }
                else
                {
                    Console.WriteLine("The intersection of " + ui1 + " and " + cb1 + " with " + ui2 + " and " 
                        + cb2 + " is null." );
                }
            }
        }

        return returnValue;
    }
//Copy creates and returns an identical copy of the current permission.
    private bool CopyDemo()
    {
        bool returnValue = true;

        UIPermissionWindow ui1;
        UIPermissionClipboard cb1;
        UIPermission uiIdPerm1,uiIdPerm2;

        UIGenerator uiGen1 = new UIGenerator();
        UIGenerator uiGen2 = new UIGenerator();

        uiGen1.ResetIndex();
        while(uiGen1.CreateUI(out uiIdPerm1, out ui1, out cb1)) 
        {
            if(uiIdPerm1 == null) continue;
            uiGen2.ResetIndex();
            Console.WriteLine("********************************************************\n");
            try
            {        
                uiIdPerm2 = (UIPermission)uiIdPerm1.Copy();
                Console.WriteLine("Result of copy = " + uiIdPerm2.ToString());

            }
            catch(Exception e) 
            {
                Console.WriteLine("The copy failed :" + uiIdPerm1.ToString() + e);
                continue;
            }
        }
        return returnValue;
    }
// ToXml creates an XML encoding of the permission and its current state; 
// FromXml reconstructs a permission with the specified state from the XML encoding. 
    private bool ToFromXmlDemo()
    {
        bool returnValue = true;

        UIPermissionWindow ui1;
        UIPermissionClipboard cb1;
        UIPermission uiIdPerm1,uiIdPerm2;
        UIGenerator uiGen1 = new UIGenerator();
        UIGenerator uiGen2 = new UIGenerator();
        uiGen1.ResetIndex();
        while(uiGen1.CreateUI(out uiIdPerm1, out ui1, out cb1)) 
        {
            if(uiIdPerm1 == null) continue;
            Console.WriteLine("********************************************************\n");
            uiGen2.ResetIndex();
        try
            {            
                uiIdPerm2= new UIPermission(PermissionState.None);
                uiIdPerm2.FromXml(uiIdPerm1.ToXml());
                Console.WriteLine("Result of ToFromXml = " +
                    uiIdPerm2.ToString());
    
            }
            catch(Exception e) 
            {
                Console.WriteLine("ToFromXml failed :" + uiIdPerm1.ToString() + e);
                continue;
            }
        }

        return returnValue;

    }
// Invoke all demos.
    public bool runDemo()
    {
        bool returnCode = true;
        bool tempReturnCode;

        // Call the IsSubsetOfClipboard demo.
        if(tempReturnCode= IsSubsetOfClipboardDemo())Console.Out.WriteLine("IsSubsetOfClipboard demo completed successfully.");
        else Console.Out.WriteLine("IsSubsetOfClipboard demo failed");
        returnCode=tempReturnCode && returnCode;

        // Call the IsSubsetOfWindow demo.
        if(tempReturnCode= IsSubsetOfWindowDemo())Console.Out.WriteLine("IsSubsetOfWindow demo completed successfully.");
        else Console.Out.WriteLine("IsSubsetOfWindow demo failed");
        returnCode=tempReturnCode && returnCode;

        // Call the IsSubsetOfWindowAndClipboard demo.
        if(tempReturnCode= IsSubsetOfWindowAndClipboardDemo())Console.Out.WriteLine("IsSubsetOfWindowAndClipboard demo completed successfully.");
        else Console.Out.WriteLine("IsSubsetOfWindowAndClipboard demo failed");
        returnCode=tempReturnCode && returnCode;

        // Call the Union demo.
        if(tempReturnCode= UnionDemo())Console.Out.WriteLine("Union demo completed successfully.");
        else Console.Out.WriteLine("Union demo failed.");
        returnCode=tempReturnCode && returnCode;

        // Call the Intersect demo.    
        if(tempReturnCode= IntersectDemo())Console.Out.WriteLine("Intersect demo completed successfully. ");
        else Console.Out.WriteLine("Intersect demo failed.");
        returnCode=tempReturnCode && returnCode;


        // Call the Copy demo.    
        if(tempReturnCode= CopyDemo())Console.Out.WriteLine("Copy demo completed successfully.");
        else Console.Out.WriteLine("Copy demo failed.");
        returnCode=tempReturnCode && returnCode;

        // Call the ToFromXml demo.    
        if(tempReturnCode= ToFromXmlDemo())Console.Out.WriteLine("ToFromXml demo completed successfully.");
        else Console.Out.WriteLine("ToFromXml demo failed.");
        returnCode=tempReturnCode && returnCode;

        return (  returnCode );    
    }
// Test harness.
    public static void Main(String[] args) 
    {
        try
        {
            UIPermissionDemo democase = new UIPermissionDemo();
            bool returnCode = democase.runDemo();
            if (returnCode)
            {
                Console.Out.WriteLine("UIPermission demo completed successfully.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 100;
            }
            else
            {
                Console.Out.WriteLine("UIPermission demo failed.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 101;
            }
        }
        catch(Exception e)
        {
            Console.Out.WriteLine("UIPermission demo failed");
            Console.WriteLine(e.ToString());
            Console.Out.WriteLine("Press the Enter key to exit.");
            string consoleInput = Console.ReadLine();
            System.Environment.ExitCode = 101;
        }
    }
}


// This class generates UIPermission objects.

internal  class UIGenerator
{
    private UIPermissionWindow[] myUI = 
        {UIPermissionWindow.AllWindows,UIPermissionWindow.SafeSubWindows,
            UIPermissionWindow.SafeTopLevelWindows, UIPermissionWindow.NoWindows};
    private UIPermissionClipboard[] myCB = 
        {UIPermissionClipboard.AllClipboard,  UIPermissionClipboard.OwnClipboard, UIPermissionClipboard.NoClipboard};

    private int uiIndex = 0;
    private int cbIndex = 0;

    public UIGenerator()
    {
        ResetIndex();
    }

    public void ResetIndex()
    {
        uiIndex = 0;
        cbIndex = 0;
    }
    public void ResetUIIndex()
    {
        uiIndex = 0;
    }
// Create a UIPermission object using both a UIPermission Window enumeration and a 
// UIPermissionClipboard enumeration to specify permissions.
    public bool CreateUI(out UIPermission UIPerm, out UIPermissionWindow ui, out UIPermissionClipboard cb)
    {

        if(uiIndex >= myUI.Length && cbIndex >= (myCB.Length - 1)) 
        {
            ui = UIPermissionWindow.NoWindows;
            cb = UIPermissionClipboard.NoClipboard;
            UIPerm = new UIPermission(ui, cb);
            return false;
        }

        if(uiIndex >= myUI.Length && cbIndex < (myCB.Length - 1)) 
        {
            ResetUIIndex();
            ui = myUI[uiIndex++];
            cb = myCB[++cbIndex];
            UIPerm = new UIPermission(ui, cb);
            return true;
        }

        ui = myUI[uiIndex++];
        cb= myCB[cbIndex];
        try
        {
            UIPerm = new UIPermission(ui, cb);
            return true;
        } 
        catch(Exception e)
        {
            Console.WriteLine("Cannot create UIPermission: " + ui +" "+e);
            UIPerm = new UIPermission(PermissionState.None);
            ui = UIPermissionWindow.NoWindows;
            return true;
        }
    }
// Create a UIPermission using  Create a UIPermission using the specified UIPermissionWindow 
// enumeration to set Window permissions.
public bool CreateUI(out UIPermission uiPerm, out UIPermissionWindow ui)
    {

        if(uiIndex >= myUI.Length) 
        {
            uiPerm = new UIPermission(PermissionState.None);
            ui=UIPermissionWindow.NoWindows;
            return false;
        }
        ui = myUI[uiIndex++];
        try
        {
            uiPerm = new UIPermission(ui);
            return true;
        } 
        catch(Exception e)
        {
            Console.WriteLine("Cannot create UIPermission: " + ui +" "+e);
            uiPerm = new UIPermission(PermissionState.None);
            ui = UIPermissionWindow.NoWindows;
            return true;
        }
    }
// Create a UIPermission using the specified UIPermissionClipboard enumeration to 
// set Clipboard permissions.
    public bool CreateUI(out UIPermission uiPerm,  out UIPermissionClipboard cb)
    {


        if(cbIndex >= myCB.Length) 
        {
            uiPerm = new UIPermission(PermissionState.None);
            cb = UIPermissionClipboard.NoClipboard;

            return false;
        }


        cb= myCB[cbIndex++];
        try
        {
            uiPerm = new UIPermission(cb);
            return true;
        } 
        catch(Exception e)
        {
            Console.WriteLine("Cannot create UIPermission: " + cb +" "+e);
            uiPerm = new UIPermission(PermissionState.None);
            cb = UIPermissionClipboard.NoClipboard;
            return true;
        }
    }
} //End of UIGenerator.

[C++] 
// This sample demonstrates the IsSubsetOf, Union, Intersect, Copy, ToXml and FromXml methods 
// of the UIPermission class.

#using <mscorlib.dll>
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Security; 
using namespace System::Security::Permissions; 

[assembly:CLSCompliant(true)];


// This class generates UIPermission objects.

private __gc class UIGenerator
{
private:
    UIPermissionWindow myUI[];
    UIPermissionClipboard myCB[];

    int uiIndex;
    int cbIndex;

public:
    UIGenerator()
    {
        UIPermissionWindow tempUI[] = 
        {
            UIPermissionWindow::AllWindows,UIPermissionWindow::SafeSubWindows,
            UIPermissionWindow::SafeTopLevelWindows, UIPermissionWindow::NoWindows
        };
        UIPermissionClipboard tempCB[] = 
        {
            UIPermissionClipboard::AllClipboard, UIPermissionClipboard::OwnClipboard,
            UIPermissionClipboard::NoClipboard
        };
        myUI = tempUI;
        myCB = tempCB;
        ResetIndex();
    }

    void ResetIndex()
    {
        uiIndex = 0;
        cbIndex = 0;
    }

    void ResetUIIndex()
    {
        uiIndex = 0;
    }
    // Create a UIPermission object using both a UIPermission Window enumeration and a 
    // UIPermissionClipboard enumeration to specify permissions.
public:
    bool CreateUI([Out]UIPermission** UIPerm, [Out]UIPermissionWindow* ui, [Out]UIPermissionClipboard* cb)
    {

        if(uiIndex >= myUI->Length && cbIndex >= (myCB->Length - 1)) 
        {
            *ui = UIPermissionWindow::NoWindows;
            *cb = UIPermissionClipboard::NoClipboard;
            *UIPerm = new UIPermission(*ui, *cb);
            return false;
        }

        if(uiIndex >= myUI->Length && cbIndex < (myCB->Length - 1)) 
        {
            ResetUIIndex();
            *ui = myUI[uiIndex++];
            *cb = myCB[++cbIndex];
            *UIPerm = new UIPermission(*ui, *cb);
            return true;
        }

        *ui = myUI[uiIndex++];
        *cb= myCB[cbIndex];
        try
        {
            *UIPerm = new UIPermission(*ui, *cb);
            return true;
        } 
        catch(Exception* e)
        {
            Console::WriteLine(S"Cannot create UIPermission: {0} {1}", __box(*ui), e);
            *UIPerm = new UIPermission(PermissionState::None);
            *ui = UIPermissionWindow::NoWindows;
            return true;
        }
    }
    // Create a UIPermission using  Create a UIPermission using the specified UIPermissionWindow 
    // enumeration to set Window permissions.
public:
    bool CreateUI([Out]UIPermission** uiPerm, [Out]UIPermissionWindow* ui)
    {

        if(uiIndex >= myUI->Length) 
        {
            *uiPerm = new UIPermission(PermissionState::None);
            *ui=UIPermissionWindow::NoWindows;
            return false;
        }
        *ui = myUI[uiIndex++];
        try
        {
            *uiPerm = new UIPermission(*ui);
            return true;
        } 
        catch(Exception* e)
        {
            Console::WriteLine(S"Cannot create UIPermission: {0} {1}", __box(*ui), e);
            *uiPerm = new UIPermission(PermissionState::None);
            *ui = UIPermissionWindow::NoWindows;
            return true;
        }
    }
    // Create a UIPermission using the specified UIPermissionClipboard enumeration to 
    // set Clipboard permissions.
public:
    bool CreateUI([Out]UIPermission** uiPerm,  [Out]UIPermissionClipboard* cb)
    {


        if(cbIndex >= myCB->Length) 
        {
            *uiPerm = new UIPermission(PermissionState::None);
            *cb = UIPermissionClipboard::NoClipboard;

            return false;
        }


        *cb= myCB[cbIndex++];
        try
        {
            *uiPerm = new UIPermission(*cb);
            return true;
        } 
        catch(Exception* e)
        {
            Console::WriteLine(S"Cannot create UIPermission: {0} {1}", __box(*cb), e);
            *uiPerm = new UIPermission(PermissionState::None);
            *cb = UIPermissionClipboard::NoClipboard;
            return true;
        }
    }
}; //End of UIGenerator.

public __gc class UIPermissionDemo
{
    // The IsSubsetOf method determines whether the current permission is a subset of the specified permission.
    // This demo uses the IsSubsetOf method to determine the relationship of two 
    // UIPermissionWindow permissions and two UIPermissionClipboard permissions.
private:
    bool IsSubsetOfWindowAndClipboardDemo()
    {
        bool returnValue = true;
        UIPermissionWindow ui1,ui2;
        UIPermissionClipboard cb1, cb2;
        UIPermission* uiIdPerm1;
        UIPermission* uiIdPerm2;
        UIGenerator* uiGen1 = new UIGenerator();
        UIGenerator* uiGen2 = new UIGenerator();
        uiGen1->ResetIndex();
        while(uiGen1->CreateUI(&uiIdPerm1, &ui1, &cb1)) 
        {
            if(uiIdPerm1 == 0) continue;
            uiGen2->ResetIndex();
            Console::WriteLine(S"********************************************************\n");

            while(uiGen2->CreateUI(&uiIdPerm2, &ui2, &cb2)) 
            {
                if(uiIdPerm2 == 0) continue;
                try
                {            
                    if (uiIdPerm1->IsSubsetOf(uiIdPerm2))
                    {
                        Console::WriteLine(S"{0} and {1} is a subset of {2}  and  {3}",
                            __box(uiIdPerm1->Window), __box(uiIdPerm1->Clipboard),
                            __box(uiIdPerm2->Window), __box(uiIdPerm2->Clipboard));
                    }
                    else
                    {
                        Console::WriteLine(S"{0} and {1} is not a subset of {2} and {3}",
                            __box(uiIdPerm1->Window), __box(uiIdPerm1->Clipboard),
                            __box(uiIdPerm2->Window), __box(uiIdPerm2->Clipboard));
                    }
                }
                catch(Exception* e) 
                {
                    Console::WriteLine(S"An exception was thrown  for subset :{0}\n{1}\n{2}",
                        uiIdPerm1, uiIdPerm2, e);
                    returnValue=false;
                }
            }
        }
        return returnValue;
    }
    // Compare two UIPemissionWindow permissions.
private:
    bool IsSubsetOfWindowDemo()
    {
        bool returnValue = true;
        UIPermissionWindow ui1,ui2;
        UIPermission* uiIdPerm1;
        UIPermission* uiIdPerm2;
        UIGenerator* uiGen1 = new UIGenerator();
        UIGenerator* uiGen2 = new UIGenerator();
        uiGen1->ResetIndex();
        while(uiGen1->CreateUI(&uiIdPerm1, &ui1)) 
        {
            if(uiIdPerm1 == 0) continue;
            uiGen2->ResetIndex();
            Console::WriteLine(S"********************************************************\n");

            while(uiGen2->CreateUI(&uiIdPerm2, &ui2)) 
            {
                if(uiIdPerm2 == 0) continue;
                try
                {            
                    if (uiIdPerm1->IsSubsetOf(uiIdPerm2))
                    {
                        Console::WriteLine(S"{0} is a subset of {1}",
                            __box(uiIdPerm1->Window), __box(uiIdPerm2->Window));
                    }
                    else
                    {
                        Console::WriteLine(S"{0} is not a subset of {1}",
                            __box(uiIdPerm1->Window), __box(uiIdPerm2->Window));
                    }
                }
                catch(Exception* e) 
                {
                    Console::WriteLine(S"An exception was thrown  for subset :{0}\n{1}\n{2}",
                        uiIdPerm1, uiIdPerm2, e);
                    returnValue=false;
                }
            }
        }
        return returnValue;
    }
    // Compare two UIPermissionClipboard permissions.
private:
    bool IsSubsetOfClipboardDemo()
    {
        bool returnValue = true;
        UIPermissionClipboard cb1, cb2;
        UIPermission* uiIdPerm1;
        UIPermission* uiIdPerm2;
        UIGenerator* uiGen1 = new UIGenerator();
        UIGenerator* uiGen2 = new UIGenerator();
        uiGen1->ResetIndex();
        while(uiGen1->CreateUI(&uiIdPerm1, &cb1)) 
        {
            if(uiIdPerm1 == 0) continue;
            uiGen2->ResetIndex();
            Console::WriteLine(S"********************************************************\n");

            while(uiGen2->CreateUI(&uiIdPerm2, &cb2)) 
            {
                if(uiIdPerm2 == 0) continue;
                try
                {            
                    if (uiIdPerm1->IsSubsetOf(uiIdPerm2))
                    {
                        Console::WriteLine(S"{0} is a subset of {1}",
                            __box(uiIdPerm1->Clipboard), __box(uiIdPerm2->Clipboard));
                    }
                    else
                    {
                        Console::WriteLine(S"{0} is not a subset of {1}",
                            __box(uiIdPerm1->Clipboard), __box(uiIdPerm2->Clipboard));
                    }
                }
                catch(Exception* e) 
                {
                    Console::WriteLine(S"An exception was thrown  for subset :{0}\n{1}\n{2}",
                        uiIdPerm1, uiIdPerm2, e);
                    returnValue=false;
                }
            }
        }
        return returnValue;
    }
    // Union creates a new permission that is the union of the current permission and the specified permission.
private:
    bool UnionDemo()
    {
        bool returnValue = true;
        UIPermissionWindow ui1,ui2;
        UIPermissionClipboard cb1, cb2;
        UIPermission* uiIdPerm1;
        UIPermission* uiIdPerm2;
        IPermission* uiIdPerm3;
        UIGenerator* uiGen1 = new UIGenerator();
        UIGenerator* uiGen2 = new UIGenerator();
        uiGen1->ResetIndex();
        while(uiGen1->CreateUI(&uiIdPerm1, &ui1, &cb1)) 
        {
            if(uiIdPerm1 == 0) continue;
            Console::WriteLine(S"**********************************************************\n");
            uiGen2->ResetIndex();

            while(uiGen2->CreateUI(&uiIdPerm2, &ui2, &cb2)) 
            {
                if(uiIdPerm2 == 0) continue;
                uiIdPerm3 = dynamic_cast<UIPermission*>(uiIdPerm1->Union(uiIdPerm2));
                uiIdPerm3 = uiIdPerm1->Union(uiIdPerm2);

                if(uiIdPerm3 == 0)  
                {
                    Console::WriteLine(S"The union of {0} and {1} is null.",
                        __box(ui1), __box(ui2));
                }
                else
                {
                    Console::WriteLine(S"The union of {0} and {1} with {2} and {3} = \n\t{4} and {5}",
                        __box(uiIdPerm1->Window), __box(uiIdPerm1->Clipboard),
                        __box(uiIdPerm2->Window), __box(uiIdPerm2->Clipboard),
                        __box((dynamic_cast<UIPermission*>(uiIdPerm3))->Window)->ToString(),
                        __box((dynamic_cast<UIPermission*>(uiIdPerm3))->Clipboard)->ToString());
                }

            }
        }

        return returnValue;

    }
    // Intersect creates and returns a new permission that is the intersection of the current 
    // permission and the permission specified.
private:
    bool IntersectDemo()
    {
        bool returnValue = true;
        UIPermissionWindow ui1,ui2;
        UIPermissionClipboard cb1, cb2;
        UIPermission* uiIdPerm1;
        UIPermission* uiIdPerm2;
        UIPermission* uiIdPerm3;
        UIGenerator* uiGen1 = new UIGenerator();
        UIGenerator* uiGen2 = new UIGenerator();
        uiGen1->ResetIndex();
        while(uiGen1->CreateUI(&uiIdPerm1, &ui1, &cb1)) 
        {
            if(uiIdPerm1 == 0) continue;
            Console::WriteLine(S"**********************************************************\n");
            uiGen2->ResetIndex();

            while(uiGen2->CreateUI(&uiIdPerm2, &ui2, &cb2)) 
            {
                if(uiIdPerm2 == 0) continue;
                uiIdPerm3 = dynamic_cast<UIPermission*>(uiIdPerm1->Intersect(uiIdPerm2));
                if (uiIdPerm3 != 0)
                {
                    Console::WriteLine(S"The intersection of {0} and {1} with {2} and {3} = \n\t{4} and {5}",
                        __box(uiIdPerm1->Window), __box(uiIdPerm1->Clipboard),
                        __box(uiIdPerm2->Window), __box(uiIdPerm2->Clipboard),
                        __box((dynamic_cast<UIPermission*>(uiIdPerm3))->Window)->ToString(),
                        __box((dynamic_cast<UIPermission*>(uiIdPerm3))->Clipboard)->ToString());
                }
                else
                {
                    Console::WriteLine(S"The intersection of {0} and {1} with {2} and {3} is null.",
                        __box(ui1), __box(cb1), __box(ui2), __box(cb2));
                }
            }
        }

        return returnValue;
    }
    //Copy creates and returns an identical copy of the current permission.
private:
    bool CopyDemo()
    {
        bool returnValue = true;

        UIPermissionWindow ui1;
        UIPermissionClipboard cb1;
        UIPermission* uiIdPerm1;
        UIPermission* uiIdPerm2;

        UIGenerator* uiGen1 = new UIGenerator();
        UIGenerator* uiGen2 = new UIGenerator();

        uiGen1->ResetIndex();
        while(uiGen1->CreateUI(&uiIdPerm1, &ui1, &cb1)) 
        {
            if(uiIdPerm1 == 0) continue;
            uiGen2->ResetIndex();
            Console::WriteLine(S"********************************************************\n");
            try
            {            
                uiIdPerm2 = dynamic_cast<UIPermission*>(uiIdPerm1->Copy());
                Console::WriteLine(S"Result of copy = {0}", uiIdPerm2);

            }
            catch(Exception* e) 
            {
                Console::WriteLine(S"The copy failed :{0}{1}", uiIdPerm1, e);
                continue;
            }
        }
        return returnValue;
    }
    // ToXml creates an XML encoding of the permission and its current state; 
    // FromXml reconstructs a permission with the specified state from the XML encoding. 
private:
    bool ToFromXmlDemo()
    {
        bool returnValue = true;

        UIPermissionWindow ui1;
        UIPermissionClipboard cb1;
        UIPermission* uiIdPerm1;
        UIPermission* uiIdPerm2;
        UIGenerator* uiGen1 = new UIGenerator();
        UIGenerator* uiGen2 = new UIGenerator();
        uiGen1->ResetIndex();
        while(uiGen1->CreateUI(&uiIdPerm1, &ui1, &cb1)) 
        {
            if(uiIdPerm1 == 0) continue;
            Console::WriteLine(S"********************************************************\n");
            uiGen2->ResetIndex();
            try
            {            
                uiIdPerm2= new UIPermission(PermissionState::None);
                uiIdPerm2->FromXml(uiIdPerm1->ToXml());
                Console::WriteLine(S"Result of ToFromXml = {0}", uiIdPerm2);

            }
            catch(Exception* e) 
            {
                Console::WriteLine(S"ToFromXml failed :{0}{1}", uiIdPerm1, e);
                continue;
            }
        }

        return returnValue;

    }
    // Invoke all demos.
public:
    bool runDemo()
    {
        bool returnCode = true;
        bool tempReturnCode;

        // Call the IsSubsetOfClipboard demo.
        if(tempReturnCode= IsSubsetOfClipboardDemo())Console::WriteLine(S"IsSubsetOfClipboard demo completed successfully.");
        else Console::WriteLine(S"IsSubsetOfClipboard demo failed");
        returnCode=tempReturnCode && returnCode;

        // Call the IsSubsetOfWindow demo.
        if(tempReturnCode= IsSubsetOfWindowDemo())Console::WriteLine(S"IsSubsetOfWindow demo completed successfully.");
        else Console::WriteLine(S"IsSubsetOfWindow demo failed");
        returnCode=tempReturnCode && returnCode;

        // Call the IsSubsetOfWindowAndClipboard demo.
        if(tempReturnCode= IsSubsetOfWindowAndClipboardDemo())Console::WriteLine(S"IsSubsetOfWindowAndClipboard demo completed successfully.");
        else Console::WriteLine(S"IsSubsetOfWindowAndClipboard demo failed");
        returnCode=tempReturnCode && returnCode;

        // Call the Union demo.
        if(tempReturnCode= UnionDemo())Console::WriteLine(S"Union demo completed successfully.");
        else Console::WriteLine(S"Union demo failed.");
        returnCode=tempReturnCode && returnCode;

        // Call the Intersect demo.    
        if(tempReturnCode= IntersectDemo())Console::WriteLine(S"Intersect demo completed successfully. ");
        else Console::WriteLine(S"Intersect demo failed.");
        returnCode=tempReturnCode && returnCode;


        // Call the Copy demo.    
        if(tempReturnCode= CopyDemo())Console::WriteLine(S"Copy demo completed successfully.");
        else Console::WriteLine(S"Copy demo failed.");
        returnCode=tempReturnCode && returnCode;

        // Call the ToFromXml demo.    
        if(tempReturnCode= ToFromXmlDemo())Console::WriteLine(S"ToFromXml demo completed successfully.");
        else Console::WriteLine(S"ToFromXml demo failed.");
        returnCode=tempReturnCode && returnCode;

        return (  returnCode );    
    }
};

// Test harness.
int main() 
{
    try
    {
        UIPermissionDemo* democase = new UIPermissionDemo();
        bool returnCode = democase->runDemo();
        if (returnCode)
        {
            Console::WriteLine(S"UIPermission demo completed successfully.");
            Console::WriteLine(S"Press the Enter key to exit.");
            Console::ReadLine();
            System::Environment::ExitCode = 100;
        }
        else
        {
            Console::WriteLine(S"UIPermission demo failed.");
            Console::WriteLine(S"Press the Enter key to exit.");
            Console::ReadLine();
            System::Environment::ExitCode = 101;
        }
    }
    catch(Exception* e)
    {
        Console::WriteLine(S"UIPermission demo failed");
        Console::WriteLine(e);
        Console::WriteLine(S"Press the Enter key to exit.");
        Console::ReadLine();
        System::Environment::ExitCode = 101;
    }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Security.Permissions

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

UIPermission メンバ | System.Security.Permissions 名前空間 | アクセス許可 | アクセス許可の要求 | UIPermissionAttribute | UIPermissionWindow | UIPermissionClipboard