Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


December 2001

IIS Scripting Solutions

RSS
Subscribe to Windows Web Solutions | See More Task Automation Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

Using the adsutil.vbs script

IIS comes with a handy script called adsutil.vbs that you can use to automate the administration of your Web sites. This generic script lets you programmatically perform many common IIS administrative tasks, including creating new Web sites; starting, stopping, pausing, and unpausing Web servers; and creating, filling, and deleting Active Server Pages (ASP) application folders. You can use adsutil.vbs to automate tasks on local and remote servers. This script is handy for working with IIS because you only need to provide the necessary parameters to execute the script. You can even use the script with batch files to achieve more functionality.

Before using adsutil.vbs, you need to be aware of a few security implications. To avoid security problems, you should not store adsutil.vbs (or any other administrative script) on a production server. A better approach is to store the script in a location that only administrators can access. In addition, you must be an administrator to perform most of the functions possible with adsutil.vbs.

By default, adsutil.vbs resides in the C:\inetpub\adminscripts folder. You can access the script three ways:

  • You can place the folder that contains the script in the system path. You can then use the script from any location on the disk.
  • You can create a shortcut to the script by specifying its full path and the necessary parameters.
  • You can access the script from the command prompt if you use the cd command to change the current directory to the directory in which the script resides (C:\inetpub\ adminscripts, by default).

Let's look at several simple tasks you can automate with adsutil.vbs. Then, let's explore how to use adsutil.vbs with batch files to achieve even more functionality.

Automating Tasks Is Just a Couple of Commands Away
As I mentioned earlier, adsutil.vbs is a generic script. Thus, when you run the script, you need to include parameters that specify the tasks you want the script to perform. For example, you can use adsutil.vbs to retrieve data about a Web server or site. Suppose you want to determine the port to which Web site number 1 on the WebServerCo1 server binds. You can use adsutil.vbs to determine the port by issuing the commands

cd \inetpub\adminscripts
Cscript.exe adsutil.vbs GET 
  W3SVC/1/ServerBindings
  -s:WebServerCo1

The first command changes the current directory to the directory that contains the script. The second command runs the script. The second command's parameter GET W3SVC/1/ServerBindings —s:WebServerCo1 is a command in and of itself. The GET command tells the script to retrieve data. The path that follows (i.e., W3SVC/1/ServerBindings) specifies what data to retrieve and where to retrieve it. The W3SVC portion of the path tells the script to access the Web server. The value of 1 tells the script that you're interested in the first Web site on that server, and ServerBindings tells the script to retrieve the server binding for that Web site. The optional —s switch specifies the server's name. You use this switch when you want to access a remote machine.

Figure 1, page 13, shows sample output from running these two commands. This output tells you that Windows Script Host (WSH) was used to run the script and that Web site number 1 (in this case, the Default Web Site) is bound to port 80.

You can use adsutil.vbs to not only retrieve data about Web servers and sites but also manipulate those Web servers and sites. For example, you can start a Web server by issuing the command

Cscript.exe adsutil.vbs START_SERVER W3SVC/1

The START_SERVER command tells the script to start the server that the path specifies. You can stop a server by replacing the START_SERVER command with the STOP_SERVER command. You can also pause and unpause a server with the PAUSE_SERVER and CONTINUE_SERVER commands, respectively. To start, stop, pause, and unpause remote servers, you can add the —s switch and specify the remote server's name, as you did with the GET command.

Using Batch Files
Now let's look at how to automate the use of adsutil.vbs with batch (.bat or .cmd) files. For example, the batch file bouncemany.bat that Listing 1, page 13, shows uses adsutil.vbs to stop and start three servers. This batch file is handy, but you won't know whether the servers stopped and started successfully unless you watch the commands execute in the console window. A better approach is to capture the output of the batch file's commands by appending the results to a log. Listing 2, page 13, contains a new version of the batch file, bouncemany2.bat, that generates such a log called bounce many.log. The log notes the servers being accessed and the status of each command. The Echo commands in bouncemany2.bat create headers and delimiters to make the log easier to read.

Figure 2 shows the first few lines of a sample log. The log excerpt shows an example of the type of error message you'll receive if the script tries to access a server that's unavailable.

Any time you need to bounce servers, you can simply run bouncemany2.bat and the servers will automatically shut down and restart. You can execute bouncemany2.bat two ways. You can include the script's full path in a command such as

C:\>c:\inetpub\adminscripts\bouncemany2.bat

Or, you can first use the cd command to change the current directory to the directory that contains the script, then use only the script's filename in the command to launch the script:

C:\inetpub\adminscripts>bounce many2.bat

With either option, you can execute the script from anywhere on a system that has access to a directory containing a copy of adsutil.vbs.

A Good Tool to Learn
These examples show the power of adsutil.vbs. You can use adsutil.vbs to automate many more tasks, and you can use batch files to automate the use of adsutil.vbs. If you're going to learn how to use only one IIS script, adsutil.vbs is a good choice. You can find out more information about how to use this script at http://www.microsoft.com/windows2000/en/advanced/iis/default.asp?url=/windows2000/en/advanced/iis/htm/adminsamples/iiasabt.htm.

End of Article



Reader Comments
good work,i've found what i need ,thank u so much.

adktd October 21, 2003


is there anyway to retirve hosted sites/virtual direcotires name in C# application

Anonymous User December 14, 2004


is there anyway to retirve hosted sites/virtual direcotires name in C# application
Adnan(asiddiqi@bankalfalah.com

Anonymous User December 14, 2004


i am able to get physical path of virtual directories from iis
but if i create websites not virtual directories then not able to get the physical path of websites from iis
(i m using c#)
please help

amitbatra November 15, 2008 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
CES 2009: Ballmer Announces Windows 7, Windows Live, Live Search Milestones

During his first-ever Consumer Electronics Show (CES) 2009 keynote address last night in Las Vegas, Microsoft CEO Steve Ballmer announced the pending public availability of a feature-complete Windows 7, the final version of Windows Live Essentials, and ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Where is Microsoft NetMeeting in Windows XP?

...


Task Automation Whitepapers Essential Guide to E-discovery and Recovery for Microsoft Exchange

Continuous Data Protection and Recovery for Microsoft Exchange

Protecting (You and) Your Data with Exchange Server 2007

Related Events Delivering Reliable and Effective Web-Based Applications

Making Web Application Perform Better: What to Watch, How to Watch It, and How to Fix It

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2009 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing