C#列表所有IIS站点以及相关站点属性
2006-11-23 17:44
459 查看
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.DirectoryServices;
using System.Reflection;
using System.Text.RegularExpressions;
int TotalServerCount=0;
DirectoryEntry rootfolder = new DirectoryEntry("IIS://localhost/W3SVC");
//TotalServerCount=rootfolder.Children.SchemaFilter.Count;
foreach (DirectoryEntry child in rootfolder.Children)
{
if (child.SchemaClassName == "IIsWebServer")
{
TotalServerCount+=1;
}
}
//循环获取所有站点详细属性写入数组中
string [] arrayServerID = new string[TotalServerCount];//站点标识符
string [] arrayServerIP = new string[TotalServerCount];//站点主机头
string [] arrayServerPort = new string[TotalServerCount];//站点主机头
string [] arrayServerHeader = new string[TotalServerCount];//站点主机头
string [] arrayServerPath = new string[TotalServerCount];//站点主机头
string [] arrayServerComment = new string[TotalServerCount];//站点主机头
string [] arrayServerBinds = new string[TotalServerCount];//站点主机头
string currentServerBindings;//绑定主机头IP端口字符串
char[] a=":".ToCharArray();
string [] currentBingdings =new string[2];
int i=0;
foreach (DirectoryEntry child in rootfolder.Children)
{
if (child.SchemaClassName == "IIsWebServer")
{
arrayServerID.SetValue(child.Name.ToString(),i);
arrayServerComment.SetValue(child.Properties["ServerComment"].Value.ToString(),i);
currentServerBindings=child.Properties["ServerBindings"].Value.ToString();
currentBingdings=currentServerBindings.Split(a);
arrayServerIP.SetValue(currentBingdings[0],i);
arrayServerPort.SetValue(currentBingdings[1],i);
arrayServerHeader.SetValue(currentBingdings[2],i);
foreach (DirectoryEntry rootChild in child.Children)
{
if((rootChild.SchemaClassName == "IIsWebVirtualDir")&&(rootChild.Name.ToString()=="root"))
{
if(rootChild.Properties["Path"].Value==null)
{
arrayServerPath.SetValue("",i);
}
else
{
arrayServerPath.SetValue(rootChild.Properties["Path"].Value.ToString(),i);
}
}
}
i+=1;
}
}
//写入到datagrid中去
//循环从数组中读取数据
for(i=0;i<TotalServerCount;i++)
{
listView1.Items.Add((i+1).ToString());
listView1.Items[i].SubItems.Add(arrayServerID.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerComment.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerIP.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerPort.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerHeader.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerPath.GetValue(i).ToString());
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.DirectoryServices;
using System.Reflection;
using System.Text.RegularExpressions;
int TotalServerCount=0;
DirectoryEntry rootfolder = new DirectoryEntry("IIS://localhost/W3SVC");
//TotalServerCount=rootfolder.Children.SchemaFilter.Count;
foreach (DirectoryEntry child in rootfolder.Children)
{
if (child.SchemaClassName == "IIsWebServer")
{
TotalServerCount+=1;
}
}
//循环获取所有站点详细属性写入数组中
string [] arrayServerID = new string[TotalServerCount];//站点标识符
string [] arrayServerIP = new string[TotalServerCount];//站点主机头
string [] arrayServerPort = new string[TotalServerCount];//站点主机头
string [] arrayServerHeader = new string[TotalServerCount];//站点主机头
string [] arrayServerPath = new string[TotalServerCount];//站点主机头
string [] arrayServerComment = new string[TotalServerCount];//站点主机头
string [] arrayServerBinds = new string[TotalServerCount];//站点主机头
string currentServerBindings;//绑定主机头IP端口字符串
char[] a=":".ToCharArray();
string [] currentBingdings =new string[2];
int i=0;
foreach (DirectoryEntry child in rootfolder.Children)
{
if (child.SchemaClassName == "IIsWebServer")
{
arrayServerID.SetValue(child.Name.ToString(),i);
arrayServerComment.SetValue(child.Properties["ServerComment"].Value.ToString(),i);
currentServerBindings=child.Properties["ServerBindings"].Value.ToString();
currentBingdings=currentServerBindings.Split(a);
arrayServerIP.SetValue(currentBingdings[0],i);
arrayServerPort.SetValue(currentBingdings[1],i);
arrayServerHeader.SetValue(currentBingdings[2],i);
foreach (DirectoryEntry rootChild in child.Children)
{
if((rootChild.SchemaClassName == "IIsWebVirtualDir")&&(rootChild.Name.ToString()=="root"))
{
if(rootChild.Properties["Path"].Value==null)
{
arrayServerPath.SetValue("",i);
}
else
{
arrayServerPath.SetValue(rootChild.Properties["Path"].Value.ToString(),i);
}
}
}
i+=1;
}
}
//写入到datagrid中去
//循环从数组中读取数据
for(i=0;i<TotalServerCount;i++)
{
listView1.Items.Add((i+1).ToString());
listView1.Items[i].SubItems.Add(arrayServerID.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerComment.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerIP.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerPort.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerHeader.GetValue(i).ToString());
listView1.Items[i].SubItems.Add(arrayServerPath.GetValue(i).ToString());
}
相关文章推荐
- C#列表所有IIS站点以及相关站点属性
- C#列表所有IIS站点以及相关站点属性
- c#读取IIS中的站点相关属性代码
- C# 创建iis站点以及IIS站点属性,iis不能启动站点
- c#读取IIS中的站点相关属性代码
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- magento中根据用户的id获取用户的所有订单以及每个订单中的物品 以及物品的相关属性
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- IIS管理站点、子站点、程序池间关系,以及C#代码ServerManager实现根据站点与子站点名称获取程序池
- 获取数据库的所有用户表 以及 获取指定表的相关字段属性
- C#获取IIS所有站点及虚拟目录和应用程序(包含名称及详细信息)
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- [C#][SAMPLE][CODE][Control]RichTextBox以及相关常见属性
- C#获取IIS所有站点及虚拟目录和应用程序(包含名称及详细信息)
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值