|
|
|
ADSI allows you to connect to various Windows server
| Note |
Even though the ADSI makes you think it may apply only to Active Directory, or perhaps only to domain controllers, the interface is valid for any Windows 2000 and later server. |
The IIS ADSI provider includes an object for each key in the metabase. Thus, you can edit any of the keys in the metabase using ADSI. When you
IIsCertMapper
IIsCompressionSchemes
IIsCompressionScheme
IIsComputer
IIsCustomLogModule
IIsFilter
IIsFilters
IIsFtpInfo
IIsFtpServer
IIsFtpService
IIsFtpVirtualDir
IIsIPSecurity
IIsLogModule
IIsLogModules
IIsMimeMap
IIsMimeType
IIsWebDirectory
IIsWebFile
IIsWebInfo
IIsWebServer
IIsWebService
IisWebVirtualDir
To connect to the provider, create an object using the ADsPath . The ADsPath for each service can be found in the 'Location' part of the key in the metabase file. For example, the location for the IIsWebService is /LM/W3SVC . To connect to a specific web site, you use the IIsWebServer key. In the metabase file, the key location for the default web site is /LM/W3SVC/1 .
| Note |
When you're using the location in your code, you do not need to include the /LM
; it's used only in the
metabase
|
To bind to an object using ADSI, start by creating the object in your VBScript. ADSI uses Lightweight Directory Access Protocol (LDAP) for queries, so port 389 needs to be open on any firewall in the way. Additionally, you do need to be an administrator to run ADSI on a system. Here's the code to get the default web site object:
SET MyDefaultWebSiteObj = GetObject("IIS://
mycomputer
/W3SVC/1")
Now you can reference the default web site object with the variable MyDefaultWebSiteObj .
| Tip |
You can connect to any site you wish; all you need to do is attach to the ordinal number of the site. In previous versions of IIS, these numbers were sequential, but in IIS 6, they are generated at random-although the default web site is always number 1. You can find the
|
The IIS ADSI properties
To read the properties of an object, you can reference the property
option explicit DIM MyDefaultWebSiteObj, ServerCommentProp SET MyDefaultWebSiteObj = GetObject("IIS://
mycomputer
/W3SVC/1") ServerCommentProp = MyDefaultWebSiteObj.ServerComment Wscript.Echo ServerCommentProp SET MyDefaultWebSiteObj = nothing
All the property
Figure 9-1:
The MetaBase.xml file
The IIS ADSI methods are used to perform actions on the associated service. The following standard ASDI methods are used:
Get Retrieves the value for the object property
GetEx Works like Get , but can also retrieve multivalued properties
GetInfo Reloads the object with the property values from the metabase
GetInfoEx Same as GetInfo , but with multivalued property support
Put Sets the value for an object's property
PutEx Sets value(s) for single or multivalued properties
SetInfo Writes the properties to the metabase
Let's take a look at some code that can be used to set a value in the metabase. We'll use the ServerComment from the previous example. This code changes the comment on the web site to 'My new site' . You can use this code in a VBScript.
option explicit DIM MyDefaultWebSiteObj, SvrComment SET MyDefaultWebSiteObj = GetObject("IIS://localhost/W3SVC/1") MyDefaultWebSiteObj.Put "ServerComment", "My new site" MyDefaultWebSiteObj.SetInfo SET MyDefaultWebSiteObj = nothing
You can also use ADSI methods to perform actions on the sites
option explicit DIM DefaultWebSiteObj SET DefaultWebSiteObj = GetObject("IIS://localhost/w3svc/1") DefaultWebSiteObj.
Stop
SET DefaultWebSiteObj = nothing
To start the default web site, just use Start in place of Stop in this code.
Generally, it's better that you run these VBScripts through cscript.exe instead of wscript.exe, because any errors or messages will appear in a pop-up with wscript and will appear in the command window with cscript . You can edit anything in the metabase using the ADSI provider-it's just a matter of discovering the object that corresponds to what you want to modify.
|
|
|