What are .INF files ??


INF file

An INF file (or Setup Information file) is a plain text file used by Microsoft Windows for installation of software and drivers. INF files are most commonly used for installing device drivers for hardware components. Windows includes IExpress.exe for the creation of INF-based installations. INF files are part of the Windows Setup API.

Structure of an INF file

The structure of an INF file is very similar to that of an INI file; it contains various sections that specify the files to be copied, changes to the registry etc. All INF files contain a [version] section with a Signature value specifying the version of Windows that the INF file is meant for. The signature is commonly $CHICAGO$ (for Windows 9x) or $WINDOWS NT$ (for Windows NT/2K/XP) Most of the remaining sections are user-defined and contain information specific to the component being installed.

Purpose of .INF Files

Ask just about any device driver writer, "What is the worst part of writing Windows device drivers?" and most will reply, "Writing .INF files!" The reason for this is that the documentation on .INF files in the DDK has not provided a procedural approach to describing .INF files, such as, "If you want to accomplish X, then do Y followed by Z".

This article will describe the basics of .INF files and how they are used in the installation of a device driver.

An .INF file can do many things; however, 97% of all .INF files really only perform three tasks:

1.)Identify the driver for a particular device. This is done using one or more Hardware IDs or Compatible IDs. The system device installer will take the Hardware IDs and Compatible IDs that were reported for a device (by its bus driver), and try and find an exact character for character match in an .INF file. When a match is found, then the system device installer knows that the .INF file describes the driver(s) for the device.

2.)Copy files from the installation medium to the system. In addition to the driver binary (the .SYS file), driver packages may also include DLLs, co-installers, applications, or any other type of file.

3.)Add entries to the registry. This describes the device and its relationship to other devices, provides for device or driver specific configuration information, and describes the driver "service" to the service control manager.

Thats it. Sounds simple, doesnt it? Actually, it is pretty simple (no, Im not kidding!).

"Youre right", replied the little bear, "even a Bear of Little Brain understands that"

The two most confusing aspects of .INF files are usually:

1.)The .INF file is not 'run from the beginning to the end; individual sections in the .INF file are 'run based upon the phase of the installation process.

2.)Most of the sections in the .INF file are actually part of a well-defined hierarchy. This fact is obscured by the squashing of the hierarchy into a flat text file.


Creating International INF Files

An INF that will be used in an international market should use %strkey% tokens for all user-viewable text. The string tokens are defined in a [Strings] section, which is typically at the end of the INF file.

To create a single international INF file, the INF can have a set of locale-specific Strings.LanguageID sections, as described in the reference page for the INF Strings Section in the Windows 2000 DDK documentation.

Alternatively, you can create a separate INF for each locale. To reduce duplication and ease maintenance, you can create a main INF file with all the necessary sections and entries, except for the Strings section. Then create a second set of files, where each file contains just the Strings section for a supported locale. Concatenate the main file with each strings file to generate the locale-specific INF files.

If an INF contains characters outside the ASCII range (outside the range 0-127), the INF should be in Unicode format. To create such a file, for example, save the INF as a Unicode file from an application like Notepad. If the INF is not in Unicode format, Setup uses the current locale to translate characters. If the INF is in Unicode format, Setup uses the full character set.

commonly used sections


General Syntax Rules for INF Files

An INF file is a text file organized into named sections. Some sections have system-defined names and some sections have names determined by the writer of the INF file.

Each section contains section-specific entries, which are interpreted by Setup software (class installers, co-installers, SetupAPI). Some entries begin with a predefined keyword. These entries are called directives.

Some INF file entries are essentially pointers from one section to another, for a specific purpose. For example, an INF AddReg directive identifies a section containing entries that instruct Setup to modify the registry. These entries sometimes include additional arguments (required or optional) for Setup to interpret during installation.

Other INF file entries do not point to other sections, but simply supply information that Setup uses during installation, such as file names, registry values, hardware configuration information, flags, and so on. For example, an INF DriverVer directive supplies driver version information.

When Setup begins an installation, it first looks for an INF Version section to verify the validity of the INF file and to determine where installation files are located. It then starts the installation by finding an INF Manufacturer section, which will contain directives to INF Models sections, which in turn provide directives leading to various INF DDInstall sections, based on the hardware ID of the device being installed.

The following syntax rules govern the required and optional contents of INF files, the format of section names by using string tokens, and line format, continuation, and comments.

Sample INF File


The following is a sample INF file that demonstrates the syntax understood by the Internet Component Download service.

_________________________


;Sample INF file for CIRC3.OCX
[Add.Code]
circ3.ocx=circ3.ocx
random.dll=random.dll
mfc40.dll=mfc40.dll
example.ocx=example.ocx

[circ3.ocx]
; Lines below specify that the specified circ3.ocx (clsid, version)
; needs to be installed on the system. If it doesn't exist already,
; it can be downloaded from the given location (a .cab file).
; Note: if "thiscab" is specified instead of the file location,
; it is assumed that the desired file is present in the same .cab
; cabinet that the INF originated from. Otherwise, if the location
; pointed to is a different .cab, the new cabinet is also downloaded
; and unpacked in order to extract the desired file.
file=http://www.code.com/circ3/circ3.cab
clsid={9DBAFCCF-592F-101B-85CE-00608CEC297B}
; Note that the {}s are required when entering a in the INF file.
; This is slightly different from the HTML syntax for inserting CLSIDs
; in an tag.
FileVersion=1,0,0,143

[random.dll]
; Lines below specify that the random.dll needs to be installed in
; the system.
; If this doesn't exist already, it can be downloaded from the given
; location.
file=http:// www.code.com/circ3/random.dll
; Note that the FileVersion is optional, and it can also be left
; empty, meaning that any version is ok.
FileVersion=
DestDir=10

; DestDir can be set to 10 or 11 ( LDID_WIN or LDID_SYS by INF
; convention).
; This places files in \Windows or \Windows\System, respectively.
; If no dest dir is specified (typical case), code is installed in
; the occache directory.

[mfc40.dll]
; Leaving the file location empty specifies that the installation
; needs mfc40 (version 4,0,0,5), but it should not be downloaded.
; If this file is not already present on the client machine, component
; download fails.
file=
FileVersion=4,0,0,5

[example.ocx]
; Leaving the file location empty specifies that the installation
; needs the specified example.ocx (clsid, version), but it should not
; be downloaded.
; If this file is not already present on the client machine, component
; download fails.
file=clsid={DEADBEEF-592F-101B-85CE-00608CEC297B}
FileVersion=1,0,0,143

_______________________

Order of Processing and Execution of INF Files

The [Add.Code] section is processed in the order listed, but the files are installed and set up in reverse order. This means that typically you would list the main OCX file first in the INF file, followed by dependent DLLs. The dependent DLLs are guaranteed to be installed and available at registration time of the main OCX.

Unconditional hooks, those hooks in the [Setup Hooks] section in the INF file, are executed in the order listed in that section (Hook1 executes before Hook2). Conditional hooks, those hooks in the file sections referenced by file names in the [Add.Code] section, are executed in the order of the [Add.Code] section. Between conditional hooks and file section installation/setup, conditional hooks always get executed before file section installations/setups in the same .cab file. Between two file section installations/setups, the order of file installation and setup is the reverse of the listing in the [Add.Code] section. Between two conditional hooks, the order is the same as that listed in the [Add.Code] section. Note this different ordering rule between conditional hooks and file section installation and setup.


INF Size Limits

* A Windows 9x/Me INF file cannot be larger than 64 kilobytes. There is no practical limit to the size of an INF file for NT-based systems.
* The maximum length, in characters, of an INF file field, before string substitution and including a terminating NULL character, is 4096 (Windows Vista and later versions of Windows) and 512 (Windows Server 2003, Windows XP, and Windows 2000).
* After string substitution, the maximum length, in characters, of an INF file string is 4096, including a terminating NULL character.
* Note, however, that Plug and Play may impose a more restrictive limit for certain INF file fields that it recognizes or uses, such as device description, driver provider, and device manufacturer.

Autorun.inf, What is it?

Autorun.inf is the primary instruction file associated with the Autorun function. Autorun.inf itself is a simple text-based configuration file that tells the operating system which executable to start, which icon to use, and which additional menu commands to make available. In other words, autorun.inf Windows how to deal open the presentation and treat the contents of the CD.

The entire sequence is initiated when the "disk change notifcation" polling discovers a new disk in the CD or DVD ROM drive. Then, if the "Auto insert notification" feature is enabled (it is by default), Windows checks in the new disk's root directory for the existence of an "autorun.inf" file. If found, Windows then reads and follows the specific instructions this file defines. If no autorun.inf file is found, then Windows refers to the new disk by its serial number and executes the default actions associated with the (data or audio) content on the disk.


Autorun.inf Defines the following:


**The process or application that will automatically run when a disk is inserted Automatically run when CD is inserted
**Optionally, one can define the process or application that will run for specific Operating environments. Icon Representing CD or DVD
**The icon that will represent your application's CD or DVD when the drive is viewed with My Computer or Explorer.
**Menu Commands when CD-ROM is clicked Menu commands displayed when the user right-clicks the CD-ROM icon from My Computer or Explorer.


A simple Autorun.inf example:

[autorun]
open=autorun.exe
icon=autorun.ico

A complex Autorun.inf example:

This example is used in the following section for complete definition and descriptions.
________________________________________

[autorun]
open=filename.exe /argument1
icon=\foldername\filename.dll,5
[autorun.mips]
open=filenam2.exe
icon=filename.ico
[autorun.alpha]
open=filenam3.exe
icon=filename.ico
[autorun.ppc]
open=filenam4.exe
icon=filename.ico
shell\install = &Install
shell\install\command = setup.exe
shell\uninstall = &UnInstall
shell\uninstall\command = Uninstall.exe
shell\readme = &Read Me
shell\readme\command = notepad readme.txt
shell\help = &Help
shell\help\command = helpfilename.hlp


_________________________________________

Example Autorun File: Description:

[autorun] [autorun] is the primary, required section name.
open=filename.exe /argument1

Open is the keyword to determine what action to take upon insert notification.

filename.exe is the value defining the application that will be automatically started.
/argument1 is the argument, parameter or switch passed to the application being run. Logically, any command line parameters used must be supported by the application.
icon=\foldername\filename.dll,5

Icon is the keyword to determine the icon used for the disk.

filename.dll is the value defining the file containing the icon.
,5 is the argument to the icon resource defining which icon to display.



Note: By default, the system looks for the file in the root directory of the inserted disk. If you want to access a file located in a specific folder or subdirectory, specify a path relative to the root.

Example: open = foldername\filename.exe This will not change the current directory.

Although AutoPlay is the default menu item, you can define a different command to be the default by including the following line. shell = verb

When the user double-clicks on the icon, the command associated with this entry will be carried out.
Note: a more common method of defining the icon resouce is an explicit reference to a .ico file. Example: icon=autorun.ico

Note: The icon defined representing your application's CD or DVD is the drive icon as viewed with My Computer or Explorer. Valid file types containing icons include .ICO .BMP .EXE .DLL If the file includes more than one icon, by default, the second icon in the files icon resource will be displayed.


Example Autorun File: Description:
[autorun.mips] Defining the autorun items for a mips machine
open=filenam2.exe The platform specific application to run
icon=filename2.ico The platform specific autorun icon
[autorun.alpha] Defining the autorun items for a DEC Alphamachine
open=filenam3.exe The platform specific application to run
icon=filename3.ico The platform specific autorun icon
[autorun.ppc] Defining the autorun items for a Power PC
open=filenam4.exe The platform specific application to run
icon=filename4.ico The platform specific autorun icon
shell\install = &Install The Keyword defining a menu item and the Hot key for that item
shell\install\command = setup.exe The keyword defining the operation to perform when the user selects this item
shell\uninstall = &UnInstall Additional menu item example
shell\uninstall\command = Uninstall.exe Additional menu item example
shell\readme = &Read Me Additional menu item example
shell\readme\command = notepad readme.txt Additional menu item example
shell\help = &Help Additional menu item example
shell\help\command = helpfilename.hlp Additional menu item example