Server creation, deletion, stopping, starting, configuring: these are all tasks that can keep you very busy, especially if you are an administrator of a large Internet or intranet Web site. This sample tool demonstrates how it is possible, even easy, for you to automate a large number of those tasks.
This script provides a simple interface through which you can create a new Web server. There are several steps required to accomplish this, starting with invoking GetObject on the IIS://LocalHost/W3SVC node. The IIsWebService object's ADSI method Create is used to create a new IIsWebServer object. The server object is then configured, and the new information written back to the metabase with the SetInfo method.
At this point in the script, the server is only half-way to becoming a full-fledged Web site. It now has a node in the metabase, but it is not running, nor does it have a root directory in which to store anything. To finish creating the web site, the tool creates an instance of the IIsWebVirtualDir ADSI object, then configures that object to be the new root directory for the new server. SetInfo is once again called to save the information to the metabase, and finally, if all has gone well up to this point, the server object's Start method is invoked.
Note that almost every major statement group has its own set of error-code checking. This is important when creating any tool in general, but especially tools that use the IIS metabase.
This sample is provided for educational purposes only. It has not been tested in a production environment, and Microsoft® will not provide technical support for it.
This script is available in the Internet services directory, at ...\iissamples\sdk\admin\mkwebsrv.vbs.