AFC Detect Sample

This sample is located in \Samples\afc102\AFCDetect.

Description
Using the Sample
Key Project Files
Technologies Demonstrated

Description

This sample provides an easy way to determine whether AFC is installed on a user's computer. Using this applet and a small amount of JavaScript on a Web page, AFC can be detected and the right actions taken. This allows you to avoid running applets that aren't supported on the user's computer.

The AFC Detect applet works by trying to dynamically load an AFC class (UIComponent) and trapping any exceptions that are thrown. If a ClassNotFoundException is caught, this indicates that AFC is not installed and the function returns the appropriate value. If the class can be loaded, this indicates that AFC is installed.

You can also use AFC Detect to determine which version of AFC is installed on a computer. Finally, the sample shows how to automatically install AFC if it is not found or if an earlier version is found.

Using the Sample

To use the sample

To use the AFC Detect applet in your scripts and Web pages, do the following:

  1. Include JavaScript in your Web page that prompts the applet to check if AFC is installed. For example:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
        function detectAFC()
    { 
            if (document.AFCDetect.doesSupportAFC() == 0)
                { 
                  alert("You don't have AFC installed on your computer.");
                  return 0
                } 
            else 
                { 
                 alert("AFC is installed on your computer."); 
                 return 1 
                } 
    }
    document.writeln("<applet code=AFCDetect.class name=AFCDetect width=0 height=0></applet>");
    
    //-->
    </SCRIPT>
    

    The script first loads the applet by writing the applet tag to the document. After loading the applet, the detectAFC function can be called, which, in turn, calls the doesSupportAFC function in the AFC Detect applet. The return value of doesSupportAFC indicates whether AFC is on the computer. You can customize this script; for example, you can send the user to a different page if AFC is not installed.

  2. To run this script as soon as someone loads the page, put the following tag at the top of your HTML file:
    <body onLoad="detectAFC()">
    

Advanced AFC Detection

The AFC Detect sample also supports obtaining the current version of AFC and comparing it to a given version number. This advanced AFC detection uses the following methods:

You can call these methods from JavaScript with a line such as the following:

iMajorVersionNumber = document.AFCDetect.getAFCMajorVersion()

The getAFCVersionString method returns the dot-separated major and minor version numbers. The other functions simply return the integer corresponding to that field.

AFC Setup Autoinstall

Autoinstall is a useful feature that automatically runs AFC Setup from a Web page, if necessary. The system checks for an installed version of AFC on the user's hard disk and runs the AFC Setup program if no version is found or if an older version is found.

To use AFC Setup Autoinstall, add the following tag to your HTML page:

<OBJECT CLASSID="clsid:9C06B801-F217-11d0-AA9B-0000F8052E95" 
CODEBASE="afcsetup.exe#Version=1,0,0,2223"
WIDTH=0 HEIGHT=0>
</OBJECT>

The <OBJECT> tag specifies a Microsoft® ActiveX® Control; here, it specifies the ActiveX control registration mechanism for AFC Setup.

The CLASSID parameter specifies the GUID for AFC Setup; this is a unique identifier in the registry that is checked when the page loads.

CODEBASE is the name of the program to run, followed by a number sign (#) and a version number. This version number is compared to the one stored in the registry with the GUID. If the version on the Web page is newer, the program is downloaded and runs automatically. If the page's version is older, nothing happens. There is no download unless it is necessary.

The WIDTH and HEIGHT parameters are set to 0 (zero) so that no space is allocated on the page for this control.

Key Project Files

AFCDetect.java

This class contains the doesSupportAFC method that, when called from JavaScript, determines whether AFC is installed. It also calls AFCVersionManager methods for determining which version of AFC is installed.

AFCVersionManager.java

This is the Version Manager class for AFC; it contains methods for retrieving AFC version information (major version, minor version, full version number, and version description).

Technologies Demonstrated

Package Version Management

© 1999 Microsoft Corporation. All rights reserved. Terms of use.