Microsoft HomeProductsSearchSupportShopWrite Usspacer.gif Microsoft Home
AFC Samples
 In this topic

*AFC Setup Autoinstall

*Using the AFC Detect Applet

*Advanced AFC Detection - Obtaining the Current AFC Version

 

AFC Samples   PreviousAFC Samples
    Previous AFC
Samples

 


AFC Detection Sample

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


AFC Setup Autoinstall

Autoinstall is a useful feature that allows one to run AFC Setup from a web page automatically, but only if necessary. The system checks for an installed version on the user's hard disk and runs the AFC Setup program, but only if necessary.

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, we are using 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 # and a version number. This version number is compared to the one stored in the registry with the GUID. If the version on the 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 tags are set to 0 because we don't want any space on the page allocated for this control.

Using the AFC Detect Applet

Using the AFC Detect applet in your own scripts and web pages is easy.

First, include some JavaScript that prompts the applet to check if AFC is installed. Use a script similar to:


<SCRIPT LANGUAGE="JavaScript">
<!--

    function detectAFC()
    {	   
	    if (document.AFCDetect.doesSupportAFC() == 0)
		{
		 alert("You don't have AFC installed on your machine.");
		 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. When this is loaded, you can call the detectAFC function to detect AFC. This calls the doesSupportAFC() function in the AFC Detect applet. Based on what that function returns, you can determine whether AFC is on the computer. You may want to customize this script, perhaps by sending the user to a different page if AFC is not installed.

Now you need some way to run this script. If you would like it to be run as soon as someone loads the page, put the following tag in the top of your HTML file:


<body onLoad="detectAFC()">

This runs the JavaScript detectAFC() function as soon as the page is loaded.

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, AFC is not installed, and the function returns the appropriate value. If the class could be loaded, AFC is installed.

Advanced AFC Detection - Obtaining the Current AFC Version

AFC Detect also supports obtaining the current version of AFC and comparing to a given version number. The AFC Detect applet supports the following functions:

  • public String getAFCVersionString()
  • public int getAFCMajorVersion()
  • public int getAFCMinorVersion()

You can call them from JavaScript with a line similar to:


	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. See the source AFCDetectInfo.htm for more details.

Top