Handles to Keys

The IIS Admin Base Object uses handles to refer to keys in the metabase. When the metabase is initialized at startup, a handle (METADATA_MASTER_ROOT_HANDLE) is automatically opened with read-only permissions. You can use the OpenKey method to get a handle to a key in the metabase by providing the key's path relative to this handle, such as /LM/W3SVC/2, the path to the key for the second Web server. You can also use a handle to any key as a reference point to subordinate keys. For example, if you have opened a handle to /LM/W3SVC/2 as mentioned above, you can then use this handle and the relative path, /ROOT/VDir1, with the OpenKey method to get a handle to the key /LM/W3SVC/2/ROOT/VDir1.

The master handle, METADATA_MASTER_ROOT_HANDLE, does not protect metabase data from multiple-thread access, so data retrieved using this handle may change unexpectedly in the metabase. However, a handle that you open with the OpenKey method locks the metabase data for the key, all of its ancestor keys, and all of its subordinate keys. This insures consistency of metabase data by preventing other threads from changing data in a path containing a key for which you have an open handle.

A handle opened with read-only permission to a key permits other clients to open read-only handles to that key and other keys in its path, both superior and subordinate to it. No client can open a handle with write permission to a key until all handles, read or write, have been closed by all clients to all keys in the path. In addition, once one client has opened a handle with write permission to a key, no other client can open a handle for either reading or writing to that key or to any key above it in its path, or subordinate to it. Because server performance can significantly be reduced while waiting for keys to be available for read-only handles, it is recommended that you call the CloseKey method as soon as you have finished writing data. This frees the handle and releases the key and all keys above and below it to other processes and clients.