Get properties of IIS Server

H

Hardy Wang

Hi,
I am using DirectoryEntry to access IIS properties. After searching
MSDN, I get "The Internet Information Services (IIS), and WinNT providers do
not currently support Count, so each will throw a NotSupportedException.",
so that I cannot use following codes to enumrate properties.

DirectoryEntry _iisServer = new DirectoryEntry("IIS://localhost/W3SVC");
foreach(DirectoryEntry de in _iisServer.Children) {
if (de.SchemaClassName == "IIsWebServer") {
foreach(string key in de.Properties.PropertyNames) {
foreach(object propertyValue in de.Properties[key]) {
MessageBox.Show(propertyValue.ToString(), key);
}
}
}
}

Thus I probably have to explicitly give the property name to get values:

DirectoryEntry _iisServer = new DirectoryEntry("IIS://localhost/W3SVC");
foreach(DirectoryEntry de in _iisServer.Children) {
if (de.SchemaClassName == "IIsWebServer") {
foreach (string s in de.Properties["ServerComment"] ) {
MessageBox.Show(s, "ServerComment");
}
}
}

After searching, I only found one sample
http://www.panayot.com/articles/iis.htm, there are some available IIS
properties.

My qiestion is where can I find all valid properties for IIS 5.0?

Thanks!
 
W

Willy Denoyette [MVP]

Well, or you consult the docs (msdn
http://www.microsoft.com/resources/...n/IIS/6/all/proddocs/en-us/ref_mb_aambref.asp)

or you retrieve the property names from the schema, following is a complete
sample.

using System;
using System.DirectoryServices;
using System.Collections;
using System.Reflection;
namespace Willys
{
class IIsProperties
{
string bindUser = "celeb//administrator";
string bindPwd= "Kevin111";
public void RetrieveSchema()
{
DirectoryEntry entry = new DirectoryEntry ("IIS://scenic/Schema",
bindUser, bindPwd, AuthenticationTypes.ServerBind);
ArrayList classes = new ArrayList(64);
ArrayList props = new ArrayList(256);
foreach (DirectoryEntry child in entry.Children)
{
if (String.Compare(child.SchemaClassName, "class",true) == 0)
{
classes.Add(child.Path.ToString());
}
}
foreach (string class1 in classes)
{
Console.WriteLine(class1);
RetrieveProperties(class1);
}
}
void RetrieveProperties(string path)
{
DirectoryEntry objClass = new DirectoryEntry (path, bindUser, bindPwd,
AuthenticationTypes.ServerBind);
object ads = objClass.NativeObject;
Type type = ads.GetType();
// IIS metadata has no mandatory properties
/*
object o = type.InvokeMember("MandatoryProperties",
BindingFlags.GetProperty, null, ads, null);
Console.WriteLine("******MANDATORY PROPERTIES********");
foreach(object s in (ICollection)o)
Console.WriteLine(s);
*/
Console.WriteLine("******OPTIONAL PROPERTIES********");
object o = type.InvokeMember("OptionalProperties",
BindingFlags.GetProperty, null, ads, null);
foreach(object s in (ICollection)o)
Console.WriteLine("\t" + s);
Console.WriteLine("*************************");
}

}
class Tester
{
static void Main()
{
IIsProperties iisProp = new IIsProperties();
iisProp.RetrieveSchema();
}
}
}

Willy.

Hardy Wang said:
Hi,
I am using DirectoryEntry to access IIS properties. After searching
MSDN, I get "The Internet Information Services (IIS), and WinNT providers
do
not currently support Count, so each will throw a NotSupportedException.",
so that I cannot use following codes to enumrate properties.

DirectoryEntry _iisServer = new DirectoryEntry("IIS://localhost/W3SVC");
foreach(DirectoryEntry de in _iisServer.Children) {
if (de.SchemaClassName == "IIsWebServer") {
foreach(string key in de.Properties.PropertyNames) {
foreach(object propertyValue in de.Properties[key]) {
MessageBox.Show(propertyValue.ToString(), key);
}
}
}
}

Thus I probably have to explicitly give the property name to get values:

DirectoryEntry _iisServer = new DirectoryEntry("IIS://localhost/W3SVC");
foreach(DirectoryEntry de in _iisServer.Children) {
if (de.SchemaClassName == "IIsWebServer") {
foreach (string s in de.Properties["ServerComment"] ) {
MessageBox.Show(s, "ServerComment");
}
}
}

After searching, I only found one sample
http://www.panayot.com/articles/iis.htm, there are some available IIS
properties.

My qiestion is where can I find all valid properties for IIS 5.0?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top