UIPermission Class
Assembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public NotInheritable Class UIPermission Inherits CodeAccessPermission Implements IUnrestrictedPermission 'Usage Dim instance As UIPermission
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public final class UIPermission extends CodeAccessPermission implements IUnrestrictedPermission
SerializableAttribute ComVisibleAttribute(true) public final class UIPermission extends CodeAccessPermission implements IUnrestrictedPermission
Not applicable.
Drawing and user input events in windows are user interfaces.
The permission to use windows can be one of the following: unrestricted, limited to SafeTopLevelWindows, only SafeSubWindows, or no window drawing or user input event access allowed. SafeTopLevelWindows and SafeSubWindows are restricted in title and size to prevent possible spoofing by potentially harmful code.
The permission to use the clipboard can be one of the following: unrestricted, write-only, or no clipboard access allowed. The paste limitation prevents potentially harmful applications from taking data from the clipboard without the user's consent, while still allowing the cut, copy, and paste operations when initiated by the user through keyboard commands.
The following code example shows the behavior of the UIPermission class methods.
Note: |
|---|
| The code example is intended to show the behavior of the methods, not to demonstrate their use. In general, the methods of permission classes are used by the security infrastructure; they are not typically used in applications. Generally, only the constructors are used in application code. The created instance validates or controls resource access by using inherited CodeAccessPermission methods such as Demand. |
Imports System Imports System.Security Imports System.Security.Permissions Public Class UIPermissionDemo Public Shared Sub Main(ByVal args() As String) IsSubsetOfDemo() CopyDemo() UnionDemo() IntersectDemo() ToFromXmlDemo() End Sub 'Main ' IsSubsetOf determines whether the current permission is a subset of the specified permission. Private Shared Sub IsSubsetOfDemo() Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows) Dim uiPerm2 As New UIPermission(UIPermissionWindow.SafeSubWindows) CheckIsSubsetOfWindow(uiPerm1, uiPerm2) uiPerm1 = New UIPermission(UIPermissionClipboard.AllClipboard) uiPerm2 = New UIPermission(UIPermissionClipboard.OwnClipboard) CheckIsSubsetOfClipBoard(uiPerm1, uiPerm2) End Sub 'IsSubsetOfDemo Private Shared Sub CheckIsSubsetOfWindow(ByVal uiPerm1 As UIPermission, ByVal uiPerm2 As UIPermission) If uiPerm1.IsSubsetOf(uiPerm2) Then Console.WriteLine(uiPerm1.Window.ToString() + " is a subset of " + uiPerm2.Window.ToString()) Else Console.WriteLine(uiPerm1.Window.ToString() + " is not a subset of " + uiPerm2.Window.ToString()) End If If uiPerm2.IsSubsetOf(uiPerm1) Then Console.WriteLine(uiPerm2.Window.ToString() + " is a subset of " + uiPerm1.Window.ToString()) Else Console.WriteLine(uiPerm2.Window.ToString() + " is not a subset of " + uiPerm1.Window.ToString()) End If End Sub 'CheckIsSubsetOfWindow Private Shared Sub CheckIsSubsetOfClipBoard(ByVal uiPerm1 As UIPermission, ByVal uiPerm2 As UIPermission) If uiPerm1.IsSubsetOf(uiPerm2) Then Console.WriteLine(uiPerm1.Clipboard.ToString() + " is a subset of " + uiPerm2.Clipboard.ToString()) Else Console.WriteLine(uiPerm1.Clipboard.ToString() + " is not a subset of " + uiPerm2.Clipboard.ToString()) End If If uiPerm2.IsSubsetOf(uiPerm1) Then Console.WriteLine(uiPerm2.Clipboard.ToString() + " is a subset of " + uiPerm1.Clipboard.ToString()) Else Console.WriteLine(uiPerm2.Clipboard.ToString() + " is not a subset of " + uiPerm1.Clipboard.ToString()) End If End Sub 'CheckIsSubsetOfClipBoard ' Union creates a new permission that is the union of the current permission ' and the specified permission. Private Shared Sub UnionDemo() Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows) Dim uiPerm2 As New UIPermission(UIPermissionWindow.SafeSubWindows) Dim p3 As UIPermission = CType(uiPerm1.Union(uiPerm2), UIPermission) Try If Not (p3 Is Nothing) Then Console.WriteLine("The union of " + uiPerm1.Window.ToString() + " and " + vbLf + vbTab + uiPerm2.Window.ToString() + " is " + vbLf + vbTab + p3.Window.ToString() + vbLf) Else Console.WriteLine("The union of " + uiPerm1.Window.ToString() + " and " + vbLf + vbTab + uiPerm2.Window.ToString() + " is null." + vbLf) End If Catch e As SystemException Console.WriteLine("The union of " + uiPerm1.Window.ToString() + " and " + vbLf + vbTab + uiPerm2.Window.ToString() + " failed.") Console.WriteLine(e.Message) End Try End Sub 'UnionDemo ' Intersect creates and returns a new permission that is the intersection of the ' current permission and the permission specified. Private Shared Sub IntersectDemo() Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows, UIPermissionClipboard.OwnClipboard) Dim uiPerm2 As New UIPermission(UIPermissionWindow.SafeSubWindows, UIPermissionClipboard.NoClipboard) Dim p3 As UIPermission = CType(uiPerm1.Intersect(uiPerm2), UIPermission) Console.WriteLine("The intersection of " + uiPerm1.Window.ToString() + " and " + vbLf + vbTab + uiPerm2.Window.ToString() + " is " + p3.Window.ToString() + vbLf) Console.WriteLine("The intersection of " + uiPerm1.Clipboard.ToString() + " and " + vbLf + vbTab + uiPerm2.Clipboard.ToString() + " is " + p3.Clipboard.ToString() + vbLf) End Sub 'IntersectDemo 'Copy creates and returns an identical copy of the current permission. Private Shared Sub CopyDemo() Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows) Dim uiPerm2 As New UIPermission(PermissionState.None) uiPerm2 = CType(uiPerm1.Copy(), UIPermission) If Not (uiPerm2 Is Nothing) Then Console.WriteLine("The copy succeeded: " + uiPerm2.ToString() + " " + vbLf) End If End Sub '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 Shared Sub ToFromXmlDemo() Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows) Dim uiPerm2 As New UIPermission(PermissionState.None) uiPerm2.FromXml(uiPerm1.ToXml()) Dim result As Boolean = uiPerm2.Equals(uiPerm1) If result Then Console.WriteLine("Result of ToFromXml = " + uiPerm2.ToString()) Else Console.WriteLine(uiPerm2.ToString()) Console.WriteLine(uiPerm1.ToString()) End If End Sub 'ToFromXmlDemo End Class 'UIPermissionDemo
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.
Note: