IIS Samples - Change Properties Using WMI

This sample script uses Windows Management Instrumentation (WMI) provider for IIS to change properties in the IIS metabase. The properties and computers on which you want to change them are listed in a tab-delimited text file that you create. There is a matching Active Directory Services Interface (ADSI) version of this sample.

important Important These samples are provided for educational purposes only. They are not intended to be used in a production environment, have not been tested in a production environment, and Microsoft does not provide technical support for them.

Sample Overview
Requirements
Location of the Source Code
Build and Install the Sample
Run the Sample
Sample Output
Helpdesk

Sample Overview

WMI can be used to access most resource on your computer, including IIS resources. IIS comes installed with an WMI provider that allows you to configure your metabase from script files and compiled code.

When running this sample, the following conditions must be met:

  • The property must exist at the level you specify in the file.
  • Not all properties propogate to child nodes. ConnectionTimeout does, ServerComment does not.
  • The property value must be of a string, boolean, or integer data type.
  • The file must be in ANSI format.
  • Each line in the file corresponds to one property change. A quick way to create the file that has repeated text is to use Excel where the first column is the machine name, the second column is the metabase path, the third column is the property name, the fourth column is the value you want set, and the fifth column is the node type. Then, copy all the fields and paste into Notepad. Each line is automatically tab-delimited.
  • The user of the script must be an administrator on all of the machines that are listed in the file. If the user account is not an administrator on all of the machines, but there is an account that is an administrator on all of the machines, alter the call to ConnectServer in this script to add a user name and password, or any other parameters like Locale ID.
  • Node types correspond to the element classes of the IIS WMI provider CIM_Setting class.
  • Use CIM Studio from the WMI SDK to view these classes, or open %systemroot%\system32\inetsrv\mbschema.xml, and search for '<Collection InternalName ='. Any InternalName value with the word 'Setting' in it indicates a class with writable properties. Those properties are listed underneath as '<Property'.
to top

Requirements

This sample requires the installation of the following software to function properly:

  • Windows XP Server with IIS 6.0 installed. This sample does not work on IIS versions 5.1 or earlier versions because WMI is not supported on Windows XP Professional or earlier versions.
to top

Location of the Source Code

IIS samples are included in the IIS Software Developer Kit (SDK). You can download the IIS SDK from Platform SDK Update. You can view the SDK at MSDN Online. In the table of contents at MSDN Online, click Web Development, Server Technologies, Internet Information Services (IIS), SDK Documentation, Internet Information Services, Samples.

The following source code files are required for this sample:

File Description
ChangeProperties_WMI.js A JScript file containing the sample code.
to top

Build and Install the Sample

Nothing is required to build this sample.

To install this sample, the following steps must be performed:

  1. Copy the ChangeProperties_WMI.js file to a physical folder on your computer. For example, create a folder called C:\Samples and copy the files to that folder.
  2. Use Windows Explorer to set restricted access control on the sample .dll file in its physical folder. For more information, click Start, Help and Support, and search for Access Control. WMI scripts can only be called by Administrators, but always restrict access to your script files to be extra secure.
to top

Run the Sample

In order to run this sample, follow the instructions listed below:

  1. Open a command line window by clicking Start, Run, type cmd in the text box, and click OK.

  2. Change directories until you are in the same one that contains your sample script. For example, if you saved your sample script in C:\Samples, type the following in the command window:

    cd C:\Samples
    

  3. Type the following to see instructions on using this script:

    Cscript /nologo ChangeProperties_WMI.js
    

  4. Using Notepad, create your tab-delimited text file containing the names of the computers on which you want to change properties, and the properties you want to change. Save your file in the same folder as your sample script in order to protect it with the same access control that you set on the folder. The following is the syntax for each line in the file:

    <machine name>          <metabase path>         <property name>         <value>         <node type>
    
    The following is an example of a tab-delimited text file that this sample can use: FakePre-591cb1a1461a446786d922bf21ce1521-9269da29ff654cb68d04b5721f99fd88

  5. To use the file you created above, you need to pass the name of the file to the script. For example, if you named your file C:\Samples\MyChanges.txt, you would use the following command in the command window:

    Cscript /nologo ChangeProperties_WMI.js C:\Samples\MyChanges.txt
    

to top

Sample Output

The following example of output is displayed for each successful change after you perform step 5 from Run the Sample.

Success: Server2 w3svc/ConnectionTimeout, 900 -> 999

Errors like the following are also displayed:

_** Error: setting property, line 1 **_
-2146828218 - Permission denied
ConnectionTimeout can not be set at w3svc.
to top

Help Desk

If here you do not find answers to your questions, visit the Microsoft Help and Support Web site.

Problem Possible Solution
Permission denied errors Only administrators can run WMI scripts. To keep security risks low, log on to your computer using an account that is not in the Administrators group, and then use the Run As command to run your script or executable as an administrator. From the command prompt, type runas /user: administrative_accountname "script_name".

to top