Using the Web Installer

[Previous] [Next]

If your target runtime environment is a web browser (or the Web Browser COM control in a Microsoft Visual Basic or C++ application), you can configure your application to automatically download and install the Office Web Components using the special Web Installer provided in the Office 2000 setup. Using the Microsoft Windows Installer technology, the Web Installer deploys only the OWC library and MDAC 2.1 files to the client, leaving the rest of Office 2000 on the file server.

Creating a Network Install Image

To use the Web Installer, you must first create an Office 2000 network install image on a file server. Most large corporations already do this because it provides the opportunity to preconfigure the Office setup experience and the initial application options to match company policies. If your corporation has created such an install image, you can use it as the source for the Office Web Components installation.

If your company has not set up an image, you can either use the Office Resource Kit or you can simply run the Office 2000 setup wizard using the /a command-line switch. For example, if your CD drive is D:, insert CD 1 from your Office 2000 CD set and type the following command:

 D:\setup.exe /a 

The setup wizard will run in administrative setup mode, allowing you to specify a file location for the network install image. The wizard will copy all the files from CD 1 to this directory, which consumes about 554 MB. Unfortunately, neither the Office Resource Kit nor the administrative setup allows you to copy only the subset of files needed for the Office Web Components; however, the file lists at the end of this chapter will help you determine which files you actually need. The Web Installer was built to find the necessary files in the directory structure defined on the CD and copy them to the client machine, so you cannot simply copy some of the files from the CD into a directory structure of your own choosing.

Specifying the Codebase Attribute

After creating your network install image, the next step in enabling the automatic download of the components is to add the codebase attribute to all your object tags. The codebase attribute is the key to making Microsoft Internet Explorer automatically download and run the Web Installer—if you omit the codebase attribute, Internet Explorer will fail to load the controls and will instead display the alternate HTML defined for the <object> tag.

The codebase tag tells Internet Explorer the location from which it should install a component that is not yet installed on the client's system. If the class ID defined in the <object> tag's classid attribute is not registered, or if the existing version is older than the requested version, Internet Explorer automatically uses the URL specified in the codebase attribute to download and install the component. A typical <object> tag and codebase attribute look like this:

 <object id="Spreadsheet1"   classid="CLSID:0002E510-0000-0000-C000-000000000046"   codebase=   "file:\\OfficeInstallServer\InstallShare\Msowc.cab#version=9,0,0,2710" > 

The first part of the codebase attribute (the part before the hash symbol [#]) in this example points back to a file path on a mythical file server called OfficeInstallServer with a mythical share called InstallShare. This path should point directly to the Office network install image I described earlier. The Msowc.cab file is the file your codebase attribute should reference, and it is in the root of the Office network install image.

The second part of the codebase attribute (the part after #) specifies an explicit version of the OWC library. This part of the codebase tag is optional, but it is extremely useful for forcing clients to automatically upgrade to a newer version of the library. When you include the version number, Internet Explorer checks the existing version of the component implementing the specified class ID to make sure it is the requested version or higher. If not, Internet Explorer automatically downloads the newer version and installs it.

Because of the licensing restrictions on the Office Web Components, the value in the codebase attribute must be a file: path rather than an http: path. The Web Installer will ensure that the codebase attribute starts with "file:" before installing the OWC library. If the Web Installer allowed downloading of the OWC library over the Internet, you could not guarantee that the client machine had an Office 2000 license. You can still take advantage of clients that do have the Office Web Components installed by simply writing pages without codebase attributes and offering the user a choice between static or interactive content, as I demonstrated in Chapter 9.

Running the Web Installer

As you might have noticed, the Msowc.cab file is actually quite small—86 KB to be exact. This is because this file contains only the Web Installer itself. When Internet Explorer starts an automatic download of the OWC library using the codebase attribute, it first downloads and installs the Web Installer. The Web Installer then registers itself as implementing all the class IDs of the Office Web Components so that it can masquerade as if it were the components themselves.

Internet Explorer then creates an instance of the Web Installer for each Office Web Component used in the page. Instead of displaying the real OWC control, the Web Installer displays a watermark and begins the process of installing the OWC library (and MDAC 2.1 if you do not already have it installed). When you first start the installation process, your page will look something like Figure 12-1.

click to view at full size.

Figure 12-1. The Web Installer starting a dynamic install.

The opening screen of the Web Installer verifies that the user does want to install the Office Web Components, describes the Office 2000 license requirement, and warns the user that the full download (including MDAC 2.1) can take a while over a slow connection. If the user chooses Yes in this dialog box, he or she is then shown the full end user license agreement for the components, which is depicted in Figure 12-2.

Figure 12-2. The Web Installer's End User License Agreement Dialog Box.

The content displayed in this dialog box comes from the License.txt file located in the root directory of the Office 2000 network install image you created earlier.

After the user accepts the license agreement, the Web Installer ensures that the Windows Installer—the new install engine in Office 2000 and Windows 2000—is present on the system (downloading it if necessary) and then uses that engine to install the OWC library and the MDAC 2.1 files if they are not already on the system. The Windows Installer displays a dialog box with a progress meter that informs the user how long it will take to complete the install. This dialog box is depicted in Figure 12-3.

Figure 12-3. The Windows Installer deploying the Office Web Components.

After the Web Installer finishes, it notifies Internet Explorer to reload the current page. Now that the real Office Web Components are registered, Internet Explorer creates the real controls and displays them in the page.

The Web Installer begins the download process before any code in your window_onLoad event handler executes. After the install, Internet Explorer reloads the page and then fires the window_onLoad event, giving you the opportunity to initialize the controls. Note that if the user chooses No in the first dialog box, the Web Installer halts the installation process and your window_onLoad event handler will run. However, because the controls were not installed, script that references properties and methods of the controls will fail. If you are enabling an automatic download through the Web Installer, you should use one of two methods to ensure that the controls were indeed installed:

  • Use the On Error Resume Next declaration, and then try to read one of the properties from the control, such as MajorVersion. If the control was not installed, this will fail and Err.Number will return a nonzero value.
  • Use the TypeName function to ask for the type name of the control. For example, the code TypeName(Spreadsheet1.Object) will return "Spreadsheet" if the Spreadsheet control was properly installed; otherwise, it will return "IWebInstCtl", which is the class name of the Web Installer.

Note that if any file being installed is currently in use, the Web Installer will notify the user that he or she must reboot the system before running the page. Because the Office Web Components are new to Office 2000 and since they do not upgrade existing Office 95 or 97 files, it is necessary to reboot only when another application is using one of the MDAC files. Because the Data Access Group chose to keep all its DLL names the same, it is possible that another application will be using an older version of an MDAC file, and the Web Installer cannot simply overwrite a DLL that is in use. Because forcing a reboot can be disruptive to the user, you might consider creating a special installation page, as described in the next section.

Creating an Installation Page

An installation page is a special page in your web site that knows how to check the client machine to see whether the Office Web Components are already installed. If the components have not been installed, this page will ask the user whether he or she wants to install them and will let the user continue after the installation finishes. Checking for the presence of the OWC library is also an easy way to dynamically determine whether you should return a page with an interactive control or a page with static information from a web site on the Internet.

I have implemented a simple installation page in the InstallOWC.asp file located in the Chap12 folder on the companion CD. You can use this file as is or customize it to fit the look and feel of your particular site. To call this page, use the following URL syntax:

 InstallOWC.asp?ContinueTo=URL&Codebase=CodebaseURL 

In this line, URL is the URL that you want the page to navigate to if the OWC library is installed (or after it is installed), and CodebaseURL is the value you would normally put in the codebase attribute, as I described earlier. The page will check for the existence of the OWC library—if it is installed, the page will immediately navigate to the URL specified in the ContinueTo parameter. If not, the page will return a page containing the Chart control, placing the value from the Codebase parameter into the <object> tag's codebase attribute.

Let's take a look at how this page works. The Microsoft Active Server Pages script will emit this HTML and client-side script fragment when first checking for the presence of the OWC library:

  <p id=lblChecking>Checking whether the Microsoft Office 2000 Web Components are installed...</p> <script language=vbscript> Option Explicit ' Attempt to create an Office Web Component as ' an object in memory to determine whether the OWC ' library is installed On Error Resume Next Dim objOWC Set objOWC = CreateObject("OWC.Chart.9") ' If this was successful If Err.number = 0 Then     ' And if the object reference is something     If Not(objOWC Is Nothing) Then         ' Check the MinorVersion and BuildNumber to make         ' sure it is the required version         ' (Note: Change these values if you want to require         ' a version other than the version         ' released with Microsoft Office 2000)         If objOWC.MinorVersion >= 0 And _             StrComp(objOWC.BuildNumber,"2710") = 0 Then             window.navigate "<%= Request("ContinueTo") %>"         End If 'Correct version     End If 'Components installed End If 'No error on create </script>  

The script block attempts to create the object OWC.Chart.9, and if successful (if Err.Number is 0), the script checks that the version number is acceptable. If all this checks out, the script navigates the window to the URL specified in the ContinueTo parameter and your user continues to work with your web site. Note that because the Office Web Components are marked as safe for initialization and safe for scripting, this code will not produce security warnings, meaning it is extremely unobtrusive.

If the CreateObject function fails or if the version number is not correct, the page continues by emitting this HTML fragment:

 <p id=lblInstall style="display:none"> <b>You need to install the Microsoft Office 2000 Web Components.</b> </p> <p> Installing the components might take some time over a slow connection.  To make the installation as easy as possible, you should close  any other applications you have running before starting  the installation. </p> <a href="InstallOWC.asp?ContinueTo=<%= Request("ContinueTo") %> &Codebase=<%= Request("Codebase") %>&Install=True"> <img src="PoweredByMSOWC.gif" border=none> <b>Click here to install the Microsoft Office 2000 Web Components.</b> </a> <script language=vbscript> Option Explicit lblChecking.style.display = "none" lblInstall.style.display = "" </script> 

This HTML warns the user that the download might take some time and encourages him or her to shut down all other applications in case any of the MDAC files are in use. The HTML then provides a hyperlink that returns to the same ASP page, but this time it passes the Install=True query string attribute, which causes the page to emit the following HTML and client-side script fragment:

 <p>Installing the Microsoft Office 2000 Web Components...</p> <p id=lblClick>When you see the chart, click it to continue.</p> <object id=cspace width="50%" height="50%" classid="clsid:0002E500-0000-0000-C000-000000000046" codebase="<%= Request("Codebase") %>" > </object> <script language=vbscript> '------------------------------------------------------------------------ ' Window Load Event Handler ' Sub window_onLoad()     Dim cht     ' Temporary WCChart reference     Dim c       ' Constants object reference     Dim ser     ' Temporary WCSeries reference          ' Check for successful download     On Error Resume Next     Dim nMajorVer     nMajorVer = cspace.MajorVersion     If Err.number <> 0 Then         Exit Sub     End If     On Error Goto 0          ' Create a simple literal data chart     Set c = cspace.Constants     Set cht = cspace.Charts.Add()     cht.HasLegend = True     cht.SetData c.chDimSeriesNames, c.chDataLiteral, _         Array("Forecasted Sales", "Actual Sales")     cht.SetData c.chDimCategories, c.chDataLiteral, _         Array("Quarter 1", "Quarter 2", "Quarter 3", "Quarter 4")     Set ser = cht.SeriesCollection(0)     ser.SetData c.chDimValues, c.chDataLiteral, _         Array(100000, 110000, 120000, 130000)     Set ser = cht.SeriesCollection(1)     ser.SetData c.chDimValues, c.chDataLiteral, _         Array(110000, 140000, 170000, 190000) End Sub '------------------------------------------------------------------------- ' Chart Space Click Event Handler ' Sub cspace_Click(evtinfo)     window.navigate "<%= Request("ContinueTo") %>" End Sub 'cspace_Click() '------------------------------------------------------------------------- ' Chart Space MouseMove Event Handler ' Sub cspace_MouseMove(evtinfo)     lblClick.style.fontWeight = "Bold" End Sub 'cspace_MouseMove() '------------------------------------------------------------------------- ' Document MouseOver Event Handler ' Sub document_onMouseOver()     lblClick.style.fontWeight = "" End Sub </script> 

The HTML fragment contains an <object> tag for the Chart control, specifying the codebase attribute so that Internet Explorer will begin the download process and invoke the Web Installer. When the Web Installer finishes, Internet Explorer fires the window_onLoad event and the code in that event's handler adds some literal data to the chart. When the user clicks the Chart control, the client-side code navigates the window to the URL specified in the ContinueTo parameter and the user continues to use your web site as normal.



Programming Microsoft Office 2000 Web Components
Programming Microsoft Office 2000 Web Components (Microsoft Progamming Series)
ISBN: 073560794X
EAN: 2147483647
Year: 1999
Pages: 111
Authors: Dave Stearns

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net