DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
// Find unused ID value for new web site int siteID = 1;
//得到现有的站点标识
foreach (DirectoryEntry entry in root.Children)
{
if (entry.SchemaClassName == "IIsWebServer")
{
int ID = Convert.ToInt32(entry.Name);
}
}