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());
}
新闻热点
疑难解答
图片精选