Visual Basic Concepts

Setting Safety Levels for ActiveX Components

See Also

There are two ways you can set safety levels for your downloadable components. The easiest way is to use the Package and Deployment Wizard to mark your .cab files as safe. The other option is to use the IObjectSafety interface to tell the client machine that your code is safe.

Note   IObjectSafety is an advanced coding topic that requires an understanding of the Implements interface and is intended for experienced programmers. For information on the Implements interface, see "Polymorphism" in Programming with Objects," in the Programmer's Guide.

Using the Package and Deployment Wizard

If you do not implement the IObjectSafety interface on your objects, the Package and Deployment Wizard will present you with the opportunity to set safety flags on your download package. You can select the Safe for Scripting flag, the Safe for Initialization flag, or both.

Note   If you have used the IObjectSafety interface for an object, it will not appear in the safety settings screen of the Package and Deployment Wizard.

For More Information   See "Distributing your Applications," in the Programmer's Guide for more information on using the Package and Deployment Wizard to package your controls.

Using IObjectSafety

IObjectSafety is an interface that exposes functionality to Internet Explorer's Safe for Scripting and Safe for Initialization security features. IObjectSafety should be implemented for objects that have interfaces that support untrusted clients — or those clients for which specific functionality cannot be predicted or safe usage cannot be guaranteed — such as scripts. The interface allows you to specify which parts of the object need to be protected from use.

Using IObjectSafety, you can mark your object and its parts in three ways:

There are three possible scenarios to consider for your objects:

  1. All properties and methods on your object are always safe for scripting. In this scenario, you can notify the client that your object is safe for scripting by not returning an error in the IObjectSafety_SetInterfaceSafetyOptions interface method. This allows your object to be successfully created and run.

  2. Your object is never safe for scripting. In this case, you can notify the client that your object is not safe by returning an error, E_Fail, in the IObjectSafety_SetInterfaceSafetyOptions interface method. This prevents the client from accessing any methods or properties through script.

  3. Some but not all of the properties and methods on your object are unsafe for scripting. In this case you can either notify the client that your entire object is unsafe, or notify the client that your object is safe, but disable the properties and methods that are unsafe.

For More Information   See the Internet/Intranet/Extranet Services SDK at SDK on Microsoft's Web site for more information on the IObjectSafety interface. An IObjectSafety sample application can be found in the Samples directory.