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 its subkeys. For example, if you have opened a handle to /LM/W3SVC/2, 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 may change unexpectedly in the metabase. To insure consistency of metabase data by preventing other threads from changing configuration data, always use the OpenKey method. A handle opened with the OpenKey method locks the metabase data for that key, all of its parent keys, and all of its subkeys.

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 parent keys and subkeys. A handle opened with write permission, however, does not permit a client to open a handle with write permission to a that key until all handles, read-only or write, have been closed by all clients to all keys in that path. 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 that key, and also its parent keys and subkeys, to other processes and clients.