The IIsComputer class is also the entry point to remote management of one or more IIS machines. Instead of using localhost in the pathname when calling the IIsComputer object, simply reference the remote system's machine name (e.g., iisgeekserver) or IP address. This remote-management functionality occurs through Distributed COM (DCOM). If different credentials are necessary to connect to the remote machine, you must use the ADSI IADsOpenDSObject core interface's OpenDSObject method instead of the GetObject function. The script that Listing 3 shows first uses the GetObject function to access the IIS ADSI provider, then calls the OpenDSObject method, passing the necessary username and password for authentication on the remote system. (For more information about the ADSI provider, interfaces, and constants, see "Related Reading.") A word of caution: Using a clear-text password in a script isn't a sound security practice; this article does so for demonstration purposes only. Either store the script at an extremely safe location or modify the script to prompt the administrator for his or her username and password.
The W3SVC node (IIsWebService class). IIS can host multiple services, the most popular of which are W3SVC, FTP, SMTP, and NNTP. Each of these services has its own node under the machine node. When you use the IIS://localhost/W3SVC pathname argument, you get a W3Svc object derived from the IISWebService class.
The Web site node (IIsWebServer class). A class name such as IIsWebSite (rather than IIsWebServer) would more clearly communicate the Web site node's function. Each Web site on your server is represented by a separate node. To avoid ambiguous references, IIS assigns each Web site a numerical site ID; the default Web site's ID is always 1. To reference the default Web site node in a script, therefore, use that number in the GetObject function's pathname argument. If you have more than one Web site, you can use Metabase Explorer to find each site's ID. In IIS 6.0, the IIS Manager snap-in also displays the site ID, or you can run the following command to display all sites:
iisweb.vbs /query
To find a site ID for an IIS 5.1 site, run the findweb.vbs script, which resides by default in the %windir%\Inetpub\Adminscripts folder; for IIS 5.0 and IIS 4.0 sites, the file is named findsite.vbs.
The IIS documentation details hundreds of properties on the Web site level. Most of these properties are reflected in the IIS UI, but some, such as the Realm property, have GUI support in IIS 6.0 only. The IIsWebServer class also has a few useful methods, including those that start, stop, or pause a Web site. Such methods can be handy for remotely recycling a Web site. Listing 4 shows a sample script to stop and start the default Web site. To start the site only, use the script that Listing 5 shows.
The virtual directory node (IIsWebVirtualDir class). The ROOT virtual directory node, of the IIsWebVirtualDir class, under each Web site node represents that Web site's root location. (Although a Web site's root doesn't appear as a virtual directory in the IIS Manager console, it appears as a virtual directory in the metabase.) You can set hundreds of properties on this node, including the physical path that we've been using as an example. The IIsWebVirtualDir class also supports interesting methods, including several AppCreate functions that let you create Web applications. You can also use the AppCreate function to configure an IIS application's isolation level, and recent AppCreate extensions (e.g., AppCreate3 in IIS 6.0, AppCreate 2 in IIS 5.1 and IIS 5.0) take IIS's advanced isolation capabilities into account.
After you understand the metabase's hierarchy, you're ready to learn how to set, create, and search for IIS configuration data. With this skill, you can accomplish otherwise laborious and error-prone taskssuch as resetting your Web site's home path from one drive to another or creating an identical virtual directory in 1000 Web sitesin minutes flat.
Setting Data
Listing 6 shows a sample script that sets the default Web site's authentication scheme. This script uses the GetObject function to instantiate an object that, based on its path, is mapped to the default virtual directory on our default Web site. The script uses the GetObject function to create an instance of an IIsWebVirtualDir object named oDefaultVdir. Next, the script sets the AuthFlags property to 0 to disable all authentication schemes. The script then sets Windows authentication (AuthNTLM) as the only allowed authentication scheme for the ROOT virtual directory. The script's final line calls the SetInfo function to commit the new values. You can use this type of script to set properties on a node, thereby modifying your IIS server's configuration.
Prev. page
1
2
3
[4]
5
next page