다음을 통해 공유


Configuring Metabase Properties

The following examples demonstrate the syntax for setting a metabase property using different technologies, such as Windows Management Instrumentation (WMI) (on IIS 6.0 only) and Active Directory Service Interfaces (ADSI). The code examples are written in Microsoft? Visual Basic? Scripting Edition (VBScript), JScript?, and Perl.

For VBScript and JScript language references, see Microsoft Script Technologies.

For information about PerlScript, see Active Scripting with PerlScript.

The examples are simplified to show the essential code that is needed to change a metabase property. If you use these examples, add error checking code and security checking code before using them to configure your server.

Note

When setting metabase properties, make sure you use the correct format. Incorrectly formatted metabase properties are either ignored by IIS or cause unexpected behavior.

When Property Changes Take Effect

When you change a metabase property programmatically, the change takes effect in the in-memory metabase immediately unless it requires a restart of an IIS service, like the properties that are set on application pools, or the CentralBinaryLoggingEnabled or IIs5IsolationModeEnabled properties.

When you change properties in IIS Manager, you do not need to restart IIS services.

Property changes are written to the metabase file on disk 60 seconds after the last change, when the IIS admin service is stopped, or when you select Save Configuration to Disk in IIS Manager.

Implementation Guidelines

To implement one of the VBScript, JScript, or Perl examples in a command-line administration script

  • For VBScript: Save the script file with the file name extension of .vbs and call a script with "cscript //nologo filename.vbs".

  • For JScript: Save the script file with the file name extension of .js and call a script with "cscript //nologo filename.js".

  • For Perl: Save the script file with the file name extension of .pl and call a script with "perl filename.pl".

To implement one of the VBScript, JScript, or Perl examples in an ASP page

  1. Set security on the Web application to disable anonymous access. Anonymous access to metabase properties is not allowed. The user requesting the ASP page should be an Administrator. In addition, the process executing the ASP page must have permission to modify the metabase.

  2. Add the following lines of ASP code, where the first line is at the top of the file, and "language" is "Microsoft Visual Basic Scripting Edition (VBScript)", "JScript", or "PerlScript":

    <%@ Language="language" %> 
    <% 
    insert the example code here 
    %> 
    
  3. Change instances of WScript.Echo to Response.Write, and print to Response.Write, and print to $Response->Write.

  4. Change the file name extension of your file to .asp.

  5. Install ActivePerl with PerlScript to run the Perl examples. ActivePerl can be downloaded from the ActiveState Web site.

Example Code

In the following examples, there are italicized words that must be replaced by a valid string for the example to execute properly. Replace property_name_1 and property_name_2 with metabase property names. Replace numeric_or_Boolean_value and property_name_2 with metabase property names. Replace numeric_or_Boolean_value and String_value with a valid data types for that property.

These examples demonstrate how to set a metabase property to a string, number, or Boolean value. These examples do not cover WMI situations where you need to pass in an object.

IIS 5.1 and earlier: The IIS WMI provider is not available, so the WMI examples do not run.

WMI

set providerObj=GetObject("winmgmts:/root/MicrosoftIISv2") 
set vdirObj=providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'") 
' Print out the current value of some properties: 
WScript.Echo "Before: " & vdirObj.property_name_1 & ", " & vdirObj.property_name_2 
' Set some properties: 
vdirObj.property_name_1=numeric_or_Boolean_value 
vdirObj.property_name_2="String_value" 
' Save the property changes in the metabase: 
vdirObj.Put_() 
WScript.Echo "After: " & vdirObj.property_name_1 & ", " & vdirObj.property_name_2
var providerObj=GetObject("winmgmts:/root/MicrosoftIISv2"); 
var vdirObj=providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'"); 
// Print out the current value of some properties: 
WScript.Echo("Before: " + vdirObj.property_name_1 + ", " + vdirObj.property_name_2); 
// Set some properties: 
vdirObj.property_name_1=numeric_or_Boolean_value; 
vdirObj.property_name_2="String_value"; 
// Save the property changes in the metabase: 
vdirObj.Put_(); 
WScript.Echo("After: " + vdirObj.property_name_1 + ", " + vdirObj.property_name_2);

[PerlScript]

use Win32; 
use Win32::OLE; 
my $providerObj=Win32::OLE -> GetObject("winmgmts:/root/MicrosoftIISv2"); 
my $vdirObj=$providerObj->Get("IIsWebVirtualDirSetting='W3SVC/1'"); 
# Print out the current value of some properties: 
print "Before: ", $vdirObj->{"property_name_1"}, ", ", $vdirObj->{"property_name_2"}, "\n"; 
# Set some properties: 
$vdirObj->{"property_name_1"}=numeric_or_Boolean_value; 
$vdirObj->{"property_name_2"}="String_value"; 
# Save the property changes in the metabase: 
vdirObj->Put_(); 
print "After: ", $vdirObj->{"property_name_1"}, ", ", $vdirObj->{"property_name_2"}, "\n";

ADSI

set vdirObj=GetObject("IIS://localhost/W3svc/1/Root") 
' Print out the current value of some properties: 
WScript.Echo "Before: " & vdirObj.property_name_1 & ", " & vdirObj.property_name_2 
' Set some properties: 
vdirObj.Put "property_name_1", numeric_or_Boolean_value 
vdirObj.Put "property_name_2", "String_value" 
' Save the property changes in the metabase: 
vdirObj.SetInfo 
WScript.Echo "After: " & vdirObj.property_name_1 & ", " & vdirObj.property_name_2
var vdirObj=GetObject("IIS://localhost/W3svc/1/Root"); 
// Print out the current value of some properties: 
WScript.Echo("Before: " + vdirObj.property_name_1 + ", " + vdirObj.property_name_2); 
// Set some properties: 
vdirObj.Put("property_name_1", numeric_or_Boolean_value); 
vdirObj.Put("property_name_2", "String_value"); 
// Save the property changes in the metabase: 
vdirObj.SetInfo(); 
WScript.Echo("After: " + vdirObj.property_name_1 + ", " + vdirObj.property_name_2);

[PerlScript]

use Win32; 
use Win32::OLE; 
my $vdirObj=Win32::OLE -> GetObject("IIS://localhost/W3SVC/1/Root"); 
# Print out the current value of some properties: 
print "Before: ", $vdirObj->{"property_name_1"}, ", ", $vdirObj->{"property_name_2"}, "\n"; 
# Set some properties: 
$vdirObj->{"property_name_1"}=numeric_or_Boolean_value; 
$vdirObj->{"property_name_2"}="String_value"; 
# Save the property changes in the metabase: 
$vdirObj->SetInfo();  
print "After: ", $vdirObj->{"property_name_1"}, ", ", $vdirObj->{"property_name_2"}, "\n";

You may encounter errors when running example code that you have altered. The following table lists possible errors and their causes.

Error Code

Possible Cause

0x80005006

The property does not exist, or it does not exist at the access location where you are attempting to set it.

For example, you cannot set the AdminServer property at the Web site level (W3SVC/1, W3SVC/1/ROOT) or the virtual directory level (W3SVC/1/ROOT/vdir); you can set it only at the World Wide Web Publishing Service (WWW service) level. You cannot set the AdminEmail property on any Web, File Transfer Protocol (FTP), or Simple Mail Transfer Protocol (SMTP) metabase key; you can set it only on a Network News Transfer Protocol (NNTP) metabase key.

See the Metabase Property Reference for the metabase property that you are trying to set. Use the Access Locations table to verify that you are accessing the property at a valid location. Or, you can open the MetaBase.xml file on your server and search for the property to see what locations it is set on.

0x8000500C

The data type of the property is different than the data type to which you are attempting to set it.

For example, you cannot set the AspCodepage property to a string ("English"); you can set it only to a number representing a code page (1252).