Code Examples to Configure Metabase Properties
Applies To: Windows Server 2003, Windows Server 2003 with SP1
The following examples demonstrate the syntax for setting a metabase property using different technologies, such as Windows Management Instrumentation (WMI) and Active Directory Service Interfaces (ADSI). The code examples are written in Microsoft® Visual Basic® Scripting Edition (VBScript), JScript®, and Perl.
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.
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
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.
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 %>
Change instances of WScript.Echo to Response.Write, and print to $Response->Write.
Change the file name extension of your file to .asp.
Install ActivePerl with PerlScript to run the Perl examples. ActivePerl can be downloaded from the ActiveState Web site.
Code Examples
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 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.
WMI
Microsoft Visual Basic Scripting Edition (VBScript) |
|
JScript |
|
Perl |
|
ADSI
Microsoft Visual Basic Scripting Edition (VBScript) |
|
JScript |
|
Perl |
|
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 Metabase 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 Metabase 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 Metabase Property property to a string ("English"); you can set it only to a number representing a code page (1252). |
Related Information
For information about scripting in JScript or Microsoft Visual Basic Scripting Edition (VBScript), see the Microsoft Script Technologies SDK.
For an article about scripting in PerlScript, see Active Scripting with PerlScript.
For information about WMI and ADSI, including additional examples, see IIS Administration Technologies in the IIS SDK on MSDN.