Controlling IIS programmatically
Want to control IIS through programming? This tip, excerpted from InformIT, gives some basic ideas you'll need to do just that.
Information relating to the configuration of IIS is stored in the metabase as binary values. 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
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.
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.
To read all of this tip, click over to InformIT. You have to register there, but it's free.
Did you like this tip? Email us and let us know.
This was first published in May 2001