Skip to Content
Professional Visual Basic 2012 and .NET 4.5 Programming
book

Professional Visual Basic 2012 and .NET 4.5 Programming

by Bill Sheldon, Billy Hollis, Rob Windsor, David McCarter, Gastón Hillar, Todd Herman
January 2013
Intermediate to advanced
912 pages
26h 58m
English
Wrox
Content preview from Professional Visual Basic 2012 and .NET 4.5 Programming

Managing Code Access Permission Sets

This section looks at programmatic access to permissions. The example extends the ProVB2012_Security project discussed earlier. This example illustrates how when a method fails, an exception object containing the result is generated. Note that in the case of a real-world example, you would be setting up permissions for a calling application. In many instances, you don't want a calling application to be able to access the registry, or you want a calling application to be able to read memory variables but not change them. Keep in mind that you can only limit those permissions which are already available to a user based on their identity. You can't grant access to a portion of the operating system via code that the user doesn't have access to based on their identity.

The following example first sets up the permission that is wanted and then grants the code the appropriate access level. Thee code that accesses this security object illustrates the effect of these new permissions on the code. Note you will need to add the line Imports System.IO to the top of your MainWindow.xaml.vb file for the following code to compile.

 Private Sub TestFileIOPermission() Dim oFp = New FileIOPermission( FileIOPermissionAccess.AllAccess, "C:\Temp") oFp.PermitOnly() 'Try Dim strmWrite As New IO.StreamWriter( File.Open("C:\Temp\Permission.txt", IO.FileMode.Open)) strmWrite.WriteLine("Hi there!") strmWrite.Flush() strmWrite.Close() Dim objWriter As New IO.StreamWriter( ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Visual Basic 2012 Programmer's Reference

Visual Basic 2012 Programmer's Reference

Rod Stephens

Publisher Resources

ISBN: 9781118332139Purchase book