IIS Samples - Change Properties Using ADSI

This sample scripts uses Active Directory Services Interface (ADSI) 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 Windows Management Instrumentation (WMI) version of this sample.

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

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

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

to top

 

Requirements

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

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_ADSI.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_ADSI.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. ADSI 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>
    The following is an example of a tab-delimited text file that this sample can use:
    Server1         w3svc   ConnectionTimeout       999
    Server2         w3svc/1         ServerComment   My Default Server
    Server2         w3svc/1/root    Path    c:\webroot
    Server1         msftpsvc        ConnectionTimeout       999
  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_ADSI.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 ADSI 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

© 1997-2002 Microsoft Corporation. All rights reserved.