Making the ConnectionTo get an idea of the types of data accessible from the CIM_Setting element class, you can use the CIMSettingClass.vbs script. This script also illustrates connecting to the MicrosoftIISv2 namespace and using WMI to query for IIS 6.0 configuration information. Note
CIMSettingClass.vbs Option Explicit On Error Resume Next Dim strComputer Dim wmiNS Dim wmiQuery Dim objWMIService Dim colItems Dim objItem strComputer = "." wmiNS = "/root/MicrosoftIISv2" wmiQuery = "select * from CIM_Setting" Set objWMIService = GetObject("winmgmts://" _ & strComputer & wmiNS) Set colItems = objWMIService.ExecQuery(wmiQuery) For Each objItem In colItems WScript.Echo ": " & objItem.Name Next Header InformationThe Header information section of CIMSettingClass.vbs, which follows, contains the normal Option Explicit, On Error Resume Next, and six variables. The advantage of splitting out the variables instead of including the data on the connection string is that doing so makes the script more portable and easier to modify. Use of the variables is detailed in Table 19-1. Option Explicit 'On Error Resume Next Dim strComputer Dim wmiNS Dim wmiQuery Dim objWMIService Dim colItems Dim objItem
Reference InformationThe Reference information section of the script is used to assign values to the variables that are listed in the Header information section. StrComputer is the target computerthe one that is running IIS 6.0 and the one from which you are trying to obtain information. In this case, you are targeting the server called London. You next use the variable wmiNS to hold the namespace you want to connect into. When working with IIS 6.0, you will use the /root/MicrosoftIISv2 namespace. You defined the target computer and the target WMI namespace. Next, you define your query. You use the generic "Select *" format and assign the query to the wmiQuery variable. The only tricky issue with querying WMI is how to know which class to target and what properties the class supports. For this information, the best tool is the Platform SDK, which is available at http://www.msdn.microsoft.com. You can download a copy of it and install it on your laptop. (It makes for great reading while you are sitting on the beach in Kauai. The only problem is keeping sand out of the keyboard.) Pursuant to our earlier discussions, you will query the CIM_Setting element class for names of all the read/write properties for the IIS 6.0 admin object. The last task you need to complete in the Reference section is setting the colItems variable equal to the data returned from running the ExecQuery method when you feed it your WMI query. The Reference section of the script is seen below. strComputer = "london" wmiNS = "/root/MicrosoftIISv2" wmiQuery = "select * from CIM_Setting" Set objWMIService = GetObject("winmgmts://" _ & strComputer & wmiNS) Set colItems = objWMIService.ExecQuery(wmiQuery) Worker and Output InformationThe Worker and Output information section of the script is small because most of the real work was done in the Reference information section. Because you have a collection of items that comes back from the WMI query, you need to iterate through the collection to display the information. The easiest way to iterate through the collection is to use the For Each...Next construction. To represent the present record being worked with, objItem is used as a placeholder. Once you issue the next command, you move to the next record in the stream and assign it to the objItem variable. You then simply use WScript.Echo to echo out the name of the item in the collection. The Worker and Output section of the script is seen below. For Each objItem In colItems WScript.Echo ": " & objItem.name Next ![]() |