12.6. Determine at Runtime Whether Your Code Has a Specific Permission

Problem

You need to determine at runtime whether your assembly has a specific permission, such as write access to files.

Solution

Instantiate and configure the permission you want to test for, and then pass it as an argument to the Shared method IsGranted of the class System.Security.SecurityManager.

How It Works

Using minimum permission requests, you can ensure that the runtime grants your assembly a specified set of permissions. As a result, when your code is running, you can safely assume that it has the requested minimum permissions. However, you might want to implement opportunistic functionality that your application offers only if the runtime grants your assembly appropriate ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.