共用方式為


Using Hooks

A hook is a way to override or customize the installation process of one or more pieces required for a component. There are two types of hooks—unconditional and conditional.

  • Unconditional Hooks
  • Conditional Hooks

Unconditional Hooks

Unconditional hooks are hooks that always get executed. These hooks are mentioned in the [Setup Hooks] section of the Internet Component Download INF file. A good example of an unconditional hook is a setup program. The following is an example of a case using a custom setup program to install the component. Its packaging is as follows:

  1. CODEBASE= points to an example.cab that contains an example_setup.exe, example.ocx, and example.inf file. The example_setup.exe, when run with the /q parameter, will install example.ocx silently in the windows\occache directory.

  2. example.inf has:

    
    [Setup Hooks]
    hook1=hook1
    
    [hook1]
    run=%EXTRACT_DIR%\example_setup.exe /q
    
    [Version]
    ; This section is required for compatibility on both Windows 95 and Windows NT.
    Signature="$CHICAGO$"
    AdvancedInf=2.0
    

When the Code Downloader pulls down example.cab, it trust verifies the cabinet and then processes the INF. After Windows Internet Explorer finds that there is no [Add.Code] section, it processes the [Setup Hooks] section. It extracts all the files in example.cab in a unique temporary directory and then runs the command line listed in the run= key. All the files left in the temporary directory after the completion of example_setup.exe, including example_setup.exe, are discarded.

Conditional Hooks

Conditional hooks are run only when a certain condition evaluates as TRUE. This is typically when the [Add.Code] section points to a certain piece, and that piece is not available on the client's computer. The above example of example.ocx could be rewritten using conditional hooks as follows:

  • CODEBASE= points to an example.cab that contains an example_setup.exe, example.ocx, and example.inf file. The example_setup.exe, when run with the /q parameter, will install example.ocx silently in the windows\occache directory.

  • example.inf has:

    [Add.Code]
    example.ocx=example.ocx
    
    [example.ocx]
    Clsid={...}
    hook=hook1
    
    [hook1]
    run=%EXTRACT_DIR%\example_setup.exe /q
    
    [Version]
    ; This section is required for compatibility on both Windows 95 and Windows NT.
    Signature="$CHICAGO$"
    AdvancedInf=2.0
    

When the Code Downloader sees the above INF, it processes the [Add.Code] section. When processing the example.ocx section, it sees that the CLSID (example.ocx) is not registered/available on the client computer and so proceeds to execute the hook mentioned in the hook= key when it is hook1. Execution of hook1 is identical to the previous description of the hook as an unconditional hook. When only one component is in question, it doesn't make any difference whether it's marked conditional or unconditional as the whole code download was triggered because the CLASSID attribute in the object tag could not be found on the client computer. However, when installing a component that relies on some dependency that is separately installable by itself, such as Microsoft Foundation Classes (MFC) DLLs, it is good to use conditional hooks to install them.