This article originally appeared as a Web Development Zone e-newsletter.
By Phillip Perkins
Say you create a robust intranet application, but it has limited client abilities. Therefore, you have to install a component on the client machine in order to get the functionality you need. Then you create the component in Visual Basic, wishing to distribute it to everyone in the production environment without updating every machine individually.
Internet Explorer provides the ability for you to install components on the client machine through the OBJECT tag. This allows the component to install on the fly when the user visits your page.
There are some drawbacks. If your component is not digitally signed, the client machine may not be able to install it. Also, the client must allow scripting of ActiveX components marked as safe if your component implements the IObjectSafety interface or is marked safe in the distribution package. Otherwise, the client must allow scripting of ActiveX components that aren't marked safe—which is a big security hazard.
You can circumnavigate digital signing if you can mark your component as safe. Internet Explorer will prompt the user if the component is safe to download—even if it doesn't have a signature. If it's not marked safe for scripting and initialization, you may have a problem with Internet Explorer's default safety settings.
Most of the time (especially in the local intranet zone security settings), scripting and downloading of ActiveX components marked safe are enabled. In a nutshell, the best way to mark your code safe is to implement the IObjectSafety interface. Once you implement the IObjectSafety interface and compile your component, you need to create a distribution package for the Internet.
Before you do this, there's a minor problem you should consider that involves packaging Internet cabinet files with the Visual Basic 6 Runtime and OLE Automation files. During the Packaging And Deployment Wizard's (PDW) Included Files section, one of the choices for included files is VB6 Runtime And OLE Automation Files. You have the option of including these files with your cabinet file or providing a URL for download from the Microsoft site. I've tried both, and they both have given me problems. However, there is an alternative.
Download the VB6 Runtime setup file from Microsoft and add this file to your project directory. Next, start the PDW and make sure this file is in your package. Unselect the VB6 Runtime And OLE Automation option and continue with all the defaults for the PDW. Make sure to mark your component safe for scripting and initialization.
Once this is complete, you'll need to customize the INF file that is included in your cabinet file. If your project was called Project1, then your cabinet file is most likely called Project1.cab, and the INF file that you'll need to customize is called Project1.INF. This file is located under [Project Directory]\Package\Support if you went with all the default options. Open this file in an editor and locate the following code:
Change this code to:
This code installs the VB6 Runtime files through the VB6 Runtime installation program. Once this is complete, your code will be functional.
Underneath the Package\Support directory, there will be a batch file with the same name as your project (e.g., Project1.BAT). This file will recreate the cabinet file with the changes that you've made to the INF file. After you've recreated your cabinet file, you can copy this file to your Web server.
When you create the Internet package with the PDW, it will create an HTM file (e.g., Project1.HTM) with the appropriate OBJECT tag syntax. You can copy this syntax and place it in your page. Be sure to replace the CODEBASE attribute with the appropriate path to your Internet cabinet file.
Phillip Perkins is a contractor with Ajilon Consulting. His experience ranges from machine control and client/server to corporate intranet applications.