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());
}
新聞熱點
疑難解答
圖片精選