Administering IIS Programmatically
IIS offers tools that enable you to administer services using scripts or applications. The information that you manipulate and work with is stored in what is known as the metabase.
The metabase is a memory-resident data store that offers fast access to the stored information because the data doesn't have to come from a disk. As most of us are already aware, disk access has not quite made it to the speed of memory access yet.
Information relating to the configuration of IIS is stored in the metabase as binary values. In order to manipulate these values, you use the IIS Admin Objects. There are IIS Admin Objects that correspond to specific key types in the metabase. By using ASP or scripts, you can create your own applications for remotely administering your IIS server.
There are two ways to program IIS: You can use the IIS Admin Objects, which is what we will be covering in this chapter, or you can use the IIS Admin Base Object. The IIS Admin Base Object provides you with more advanced programming capabilities.
The IIS Admin Base Object is a low-level interface used with COM+–compliant languages such as C++. You use the IMSAdminBase interface to work with the IIS Admin Base Object. Using this interface and the C++ programming language, you can create applications to manipulate the IIS configuration by gaining access to the metabase keys and values.
In order to access this functionality, you work with what are known as handles. These handles refer to the keys in the metabase. You need to use the OpenKey method to gain access to a handle for a metabase key. You provide the full metabase path to the key. An example would be /LM/MSFTPSVC/1. This path points to the first FTP server on the local machine.
The IIS Admin Base Object has a master handle, called the METADATA_MASTER_ROOT_HANDLE. Although this is the master handle, it does not offer any protection in relation to multiple-thread access of the metabase. This means that you can have a multithreaded application accessing the metabase, and one thread may change a key's value without another thread being aware of this change. This may be an issue if one thread's execution depends on the value stored in another key. If that value is inadvertently changed, it may cause a malfunction in the application.
The IIS Base Admin Object makes use of inheritance as well. This means that you can assign a value to a root object or parent object and indicate that each subkey or subobject should inherit these settings. This feature will apply settings across an entire server or site. It can be overridden by specifying a new setting for individual objects.
When dealing with the IIS Admin Base Object, you will work with some user types. These user types allow you to assign a classification to your identifiers by application. IIS currently uses four user types:
IIS_MD_UT_FILE—Is used for directory and file properties
IIS_MD_UT_SERVER—Configures server parameters
IIS_MD_UT_WAM—Deals with Web application management
ASP_MD_UT_APP—Configures ASP applications
You can download the Windows 2000 Platform Software Development Kit (SDK) from the Microsoft Web site, at http://msdn.microsoft.com/downloads/sdks/platform/platform.asp.
The bottom of the page breaks the SDK into components so that you can download only what you require. This platform SDK provides a wealth of information on using the IIS Admin Base Object to develop applications for IIS manipulation.
The IIS Admin Objects that I will be presenting are known as automation-enabled. This means that they expose their interfaces to languages such as Visual Basic, VBScript, C++, and JScript for manipulation. They are based on the Active Directory Service Interfaces (ADSI).
I will delve into these objects and the ADSI a little later in the chapter, but first I need to introduce you to the metabase. After all, this is where the configuration information for IIS 5.0 is stored, and it is what you will be manipulating with the IIS Admin Objects.