# WMI Provider

Taking advantage of operating system features, IIS introduces a set of programming interfaces using Windows Management Instrumentation (WMI) that provide more powerful and flexible ways to administer your web sites. The IIS WMI provider offers a better alternative to ADSI for managing the metabase and COM admininstrative objects, such as the IIS Admin objects, programmatically.

## About Windows Management Instrumentation

The Windows Management Instrumentation (WMI) is used by Windows 2000, management tools and scripts to manage systems composed of numerous devices, resources and applications. WMI technology enables these systems and components to be represented using the Common Information Model (CIM). CIM can model anything in the managed environment regardless of data source location by providing a consistent and unified view of all types of logical and physical objects. Managed objects are represented using object-oriented constructs such as classes. These classes include properties that describe data and methods that describe behavior. In addition to data modeling, WMI offers a powerful set of base services that include query-based information retrieval and event notification. Access to these services and to the management data is made possible with a single Component Object Model (COM) programming interface. Complete WMI documentation is available from MSDN and titled "WMI Reference."

## About the IIS WMI Provider

The IIS Windows Management Instrumentation (WMI) provider acts as an intermediary between WMI and one or more managed objects, such as the metabase. When a management application, such as a script, sends a request for data or invokes a method, the provider accesses the managed object and returns the requested information to the application.

The IIS WMI provider is designed to provide equal functionality as the IIS ADSI provider for metabase configuration and IIS management tasks. The provider accesses IIS metabase data through COM object interfaces, allowing your application to access the metabase schema and methods on objects instantiated from the metabase. The WMI provider establishes relationships between objects, allowing you to tie together the various objects and all the objects contained within it, like a virtual directory and all the directories and virtual directories contained within.

The WMI provider reads a metabase as a database of records, where each record is represented as an instance of a class. Each instance can then be queried to determine content, state, associations, properties, and the like. Management tasks can then be performed using the instance of the class.

## ADSI/WMI Provider Comparison

The WMI schema is congruent with the IIS ADSI Admin Objects schema, differing only in object and data models. The two offer equivalent functionality. Therefore, a script can be written for a similar task using both the ADSI and WMI models. The effects on the metabase are equivalent.

Note For this beta release, default property values in ADSI schema are not supported. The WMI provider returns NULL.

The following table compares the architecture and features of the IIS ADSI provider with those of the IIS WMI provider.

Issue | ADSI provider | WMI provider
--- | --- | ---
    Query capabilities
    No
    Yes, by querying the returned
    class instances.
    Object model
    COM
    COM
    Extensible schema
    Yes
    No, but yes for future versions
    Access routes
    Scripts and programs
    Scripts and programs
    Association of related data
    Properties are related
    to metabase keys
    by containment.
    An association in WMI
    describes a relationship
    between classes and is
    in itself defined by a class.
    This powerful concept allows
    management information
    about an entire system
    of related components
    to be viewed and traversed for tasks
    such as troubleshooting.
    Navigating associations
    to other classes are
    not necessitated by containment.
    Container object
    Yes.
    You can use the ADSI container
    object methods of the
    IIS Admin Objects
    to manipulate keys in
    the metabase.
    You can create, delete,
    and move keys by creating,
    deleting, and moving
    IIS Admin Objects
    within container objects.
    You can also enumerate
    contained objects
    such as virtual directories
    or servers
    with container object methods.
    Supports property inheritance.
    Associations are used to approximately
    model metabase containment.

## WMI provider scenarios and script samples

Samples that illustrate the benefits of the WMI provider follow. These are offered only as examples and are not intended for production use.

### Creating a web site

An administrator must create a web site that includes a set of virtual directories. The following script illustrates how it is possible create a web site and all related directories by using the WMI provider for IIS.

var strWMIProvider = "winmgmts:root/MicrosoftIISv2";

var providerObj;

// Get WMI provider instance

var providerObj = GetObject(strWMIProvider);

var classObj, serverObj;

classObj = providerObj.get("IIs_WebServerSetting");

serverObj = classObj.SpawnInstance_();

serverObj.Name = siteName;

serverObj.ServerComment = "WMIsite2";

serverObj.ServerBindings = new Array(":8080:");

serverObj.AuthAnonymous = true;

serverObj.Put_();

// Creating the virtual dir

var vdirClass, vdirObj;

vdirClass = providerObj.get("IIs_WebVirtualDirSetting");

vdirObj = vdirClass.SpawnInstance_();

vdirObj.Name = siteName + "/ROOT";

vdirObj.Path = "C:\\inetpub\\wmisite";

vdirObj.AccessRead = true;

vdirObj.AccessScript = true;

vdirObj.AccessWrite = false;

//vdirObj.AccessExecute = false;

//vdirObj.AccessSource = false;

vdirObj.Put_();

//create the actual fs directory

var fsObj = new ActiveXObject("Scripting.FileSystemObject");

fsObj.CreateFolder("c:\inetpub\wmisite");

// Starts the new server

serverObj = providerObj.get("IIs_WebServer='" + siteName + "'");

serverObj.Start();

### Removing associated data

An ISP administrator wants to remove a site but doesn’t know the site’s ID. The administrator knows only the Server’s Comment. Using ADSI, the administrator would have to write code to enumerate everything beneath w3svc, then look for the site that contains the desired ServerComment. With the WMI provider, it is an easy query and Delete_(). The following script illustrates how it is possible to remove a user and all related material by using the IIS WMI provider.

var providerObj = GetObject("winmgmts:root/MicrosoftIISv2");

var siteObj = providerObj.ExecQuery("select * from IIS_WebServerSetting where ServerComment = 'WMIsite2'");

var e = new Enumerator(siteObj);

for (; !e.atEnd(); e.moveNext()) { e.item().Delete_();

}

### Query for data

An administrator must discover all virtual directories that have write permissions enabled. Using the IIS WMI provider, by executing a quick query on the IIS WMI provider, searching for all Iis_WebVirtualDirSetting objects to see if their AccessWrite property is set. The administrator could then cycle through the array of instances returned and perform whatever action needed, such as setting the AccessWrite bit to FALSE. The following Jscript illustrates how it is possible to query for this data and to set the AccessWrite bit accordingly.

var objProvider = var objProvider = GetObject("winmgmts://ericdetest/root/MicrosoftIISv2");

var arrVdirs = objProvider.ExecQuery("select * from IIs_WebVirtualDirSetting where AccessWrite = true");

if (arrVdirs.Count > 0) {

WScript.Echo("These virtual directories have write permission set to true:");

for (e = new Enumerator(arrVdirs); ! e.atEnd(); e.moveNext()) {

WScript.Echo(e.item().Name);

e.item().AccessWrite = "FALSE";

e.item().Put_();

}

}

else {

WScript.Echo("No vdirs have write permission set");

}

© 1997-2001 Microsoft Corporation. All rights reserved.

(The following words are used by Search; they are not intended to be displayed on the page.) keys, key, property, properties, config, configure, configuration, metabase, WMI, WMI provider,