195 lines
10 KiB
HTML
195 lines
10 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||
<HTML>
|
||
<HEAD>
|
||
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
|
||
<TITLE>WMI Provider</TITLE>
|
||
<SCRIPT LANGUAGE="JavaScript">
|
||
<!--
|
||
TempString = navigator.appVersion
|
||
if (navigator.appName == "Microsoft Internet Explorer"){
|
||
// Check to see if browser is Microsoft
|
||
if (TempString.indexOf ("4.") >= 0){
|
||
// Check to see if it is IE 4
|
||
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
|
||
}
|
||
else {
|
||
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
|
||
}
|
||
}
|
||
else if (navigator.appName == "Netscape") {
|
||
// Check to see if browser is Netscape
|
||
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
|
||
}
|
||
else
|
||
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
|
||
//-->
|
||
</script>
|
||
<SCRIPT LANGUAGE="VBScript">
|
||
<!--
|
||
Sub Window_OnLoad()
|
||
Dim frmContents
|
||
On Error Resume Next
|
||
If Not Parent Is Nothing Then
|
||
Set frmContents = Parent.Contents
|
||
If Not frmContents Is Nothing Then
|
||
frmContents.Window.TOCSynch_Click
|
||
End If
|
||
End If
|
||
End Sub
|
||
//--></SCRIPT><META NAME="DESCRIPTION" CONTENT="Internet Information Services reference information">
|
||
<META HTTP-EQUIV="PICS-Label" CONTENT='(PICS-1.1 "<http://www.rsac.org/ratingsv01.html>" l comment "RSACi North America Server" by "inet@microsoft.com <mailto:inet@microsoft.com>" r (n 0 s 0 v 0 l 0))'>
|
||
<META NAME="MS.LOCALE" CONTENT="EN-US">
|
||
<META NAME="MS-IT-LOC" Content="Internet Information Services">
|
||
</HEAD>
|
||
|
||
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
|
||
|
||
<H1><A NAME="_k2_wmi_provider"></A><SUP></SUP>WMI Provider</H1>
|
||
|
||
<P>Windows Management Instrumentation (WMI) provides a way for administrators to leverage Windows® 2000 features. To leverage WMI capabilities, IIS has developed the IIS WMI provider, which provides a set of programming interfaces that offer more powerful and flexible ways to administer your Web sites. The WMI provider offers a better alternative to ADSI to manage configuration in the metabase. </P>
|
||
|
||
<H1>About WMI</H1>
|
||
|
||
<P>Windows 2000 management tools and scripts use WMI to manage systems composed of numerous devices, resources, and applications. With WMI technology, these systems and components are 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 logical and physical objects. Managed objects are represented using object-oriented constructs, such as classes. These classes include properties that describe data and methods, and the data and methods 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 (COM) programming interface. Complete WMI documentation is available from MSDN and titled "WMI Reference."</P>
|
||
|
||
<H1>About the IIS WMI Provider</H1>
|
||
|
||
<P>The IIS WMI provider is designed to provide equal functionality as the IIS ADSI provider for metabase configuration and IIS management tasks. The IIS WMI provider accesses a managed object, specifically the IIS metabase, by providing instances of IIS configuration classes to WMI. The IIS WMI classes access the metabase through COM object interfaces; class instances allow your application to access the metabase schema. The IIS 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. </P>
|
||
|
||
<P>The WMI provider reads the 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, and properties. Management tasks can then be performed using an instance of the class.</P>
|
||
|
||
<H1>ADSI/WMI Provider Comparison </H1>
|
||
|
||
<P>The IIS WMI schema is congruent with the IIS ADSI Admin Objects schema and offers equivalent functionality on the metabase. These two schemas differ only in object and data models. Therefore, a script can be written for a similar task using the ADSI model or the WMI model. </P>
|
||
|
||
<P>The following table compares the architecture and features of the IIS ADSI provider with those of the IIS WMI provider.</P>
|
||
|
||
<TABLE border=0 cellpadding=5 cols=3 frame=box rules=all>
|
||
|
||
<TR VALIGN="top">
|
||
<TD width=33%><B>Issue</B></TD>
|
||
<TD width=33%><B>ADSI provider</B></TD>
|
||
<TD width=34%><B>WMI provider</B></TD>
|
||
</TR>
|
||
|
||
<TR VALIGN="top">
|
||
<TD width=33%>Query capabilities</TD>
|
||
<TD width=33%>No</TD>
|
||
<TD width=34%>Yes, by querying the returned class instances</TD>
|
||
</TR>
|
||
|
||
<TR VALIGN="top">
|
||
<TD width=33%>Object model</TD>
|
||
<TD width=33%>COM</TD>
|
||
<TD width=34%>COM</TD>
|
||
</TR>
|
||
|
||
<TR VALIGN="top">
|
||
<TD width=33%>Extensible schema</TD>
|
||
<TD width=33%>Yes</TD>
|
||
<TD width=34%>Yes</TD>
|
||
</TR>
|
||
|
||
<TR VALIGN="top">
|
||
<TD width=33%>Access routes</TD>
|
||
<TD width=33%>Scripts and programs</TD>
|
||
<TD width=34%>Scripts and programs</TD>
|
||
</TR>
|
||
|
||
<TR VALIGN="top">
|
||
<TD width=33%>Association of related data</TD>
|
||
<TD width=33%>Properties are related to metabase keys by containment</TD>
|
||
<TD width=34%>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.</TD>
|
||
</TR>
|
||
|
||
<TR VALIGN="top">
|
||
<TD width=33%>Container object</TD>
|
||
<TD width=33%>Yes<BR>
|
||
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 <BR>
|
||
within container objects. You can also enumerate contained objects such as virtual directories or servers with container object methods. Supports property inheritance.</TD>
|
||
<TD width=34%>Yes
|
||
<P>Associations are used to approximately model metabase containment.</P>
|
||
</TD>
|
||
</TR>
|
||
</TABLE><BR>
|
||
|
||
<P> </P>
|
||
|
||
<H1>WMI provider Scenarios and Script Samples</H1>
|
||
|
||
<P>The following samples illustrate some benefits of the WMI provider. These samples are offered only as examples and are not intended for production use.</P>
|
||
|
||
<H4>Creating a Web Site</H4>
|
||
|
||
<P>An administrator must create a Web site that includes a set of virtual directories. The following script illustrates how to create a Web site and all the related directories using the IIS WMI provider.</P>
|
||
|
||
<PRE><CODE>var strWMIProvider = "winmgmts:root/MicrosoftIISv2";
|
||
var siteName = "W3SVC/3";
|
||
var providerObj;</CODE></PRE>
|
||
|
||
<P>// Get WMI provider instance</P>
|
||
|
||
<PRE><CODE>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_();</CODE></PRE>
|
||
|
||
<P>// Creating the virtual dir</P>
|
||
|
||
<PRE><CODE>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.Put_();</CODE></PRE>
|
||
|
||
<P>//create the actual fs directory</P>
|
||
|
||
<PRE><CODE>var fsObj = new ActiveXObject("Scripting.FileSystemObject");
|
||
fsObj.CreateFolder("c:\inetpub\wmisite");</CODE></PRE>
|
||
|
||
<P>// Starts the new server</P>
|
||
|
||
<PRE><CODE>serverObj = providerObj.get("IIs_WebServer='" + siteName + "'");
|
||
serverObj.Start();</CODE></PRE>
|
||
|
||
<H4>Removing Associated Data </H4>
|
||
|
||
<P>An ISP administrator wants to remove a Web site but does not know the site<74>s ID and only knows the Server<65>s Comment. Using ADSI, the administrator has to write code to enumerate everything beneath w3svc, and then look for the site that contains the desired <B>ServerComment</B>. With the WMI provider, administrators can easily remove a Web site and all related material using query and delete. </P>
|
||
|
||
<PRE><CODE>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_();
|
||
}</CODE></PRE>
|
||
|
||
<H4>Query for Data</H4>
|
||
|
||
<P>An administrator must determine all the virtual directories that have write permissions enabled. Using the underlying query support of WMI, an administrator can execute a quick query on the instances provided by the IIS WMI provider. The following code illustrates a search for all <B>Iis_WebVirtualDirSetting </B>objects, and determines if each object's <B>AccessWrite </B>property is set. An administrator can then cycle through the array of instances returned and perform whatever action is needed, such as setting the <B>AccessWrite </B>bit to FALSE. The following JScript illustrates how to query for this data and to set the <B>AccessWrite </B>bit accordingly.</P>
|
||
|
||
<PRE><CODE>var providerObj = GetObject("winmgmts:root/MicrosoftIISv2");
|
||
var arrVdirs = providerObj.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");
|
||
</CODE></PRE>
|
||
<hr class="iis" size="1">
|
||
<p align="center"><em><a href="../../../common/colegal.htm">© 1997-1999 Microsoft Corporation. All rights reserved.</a></em></p>
|
||
</BODY>
|
||
</HTML>
|