初探WEB设置IIS Imports System Imports System.DirectoryServices Imports System.IO PublicClass WebForm5Class WebForm5 Inherits System.Web.UI.Page Web 窗体设计器生成的代码#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。 <System.Diagnostics.DebuggerStepThrough()>PrivateSub InitializeComponent()Sub InitializeComponent() End Sub ProtectedWithEvents TextBox1 As System.Web.UI.WebControls.TextBox ProtectedWithEvents Button1 As System.Web.UI.WebControls.Button ProtectedWithEvents Label1 As System.Web.UI.WebControls.Label ProtectedWithEvents Label2 As System.Web.UI.WebControls.Label '注意: 以下占位符声明是 Web 窗体设计器所必需的。 '不要删除或移动它。 Private designerPlaceholderDeclaration As System.Object PrivateSub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Init 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的 '不要使用代码编辑器修改它。 InitializeComponent() End Sub #End Region PrivateSub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load '在此处放置初始化页的用户代码 IfNot Page.IsPostBack Then post1() EndIf End Sub PrivateSub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, ii AsInteger Dim txtDomain AsString=":80:"&Me.TextBox1.Text Dim root As DirectoryEntry =New DirectoryEntry("IIS://localhost/W3SVC") ForEach root In root.Children If (root.Name = Request("ID")) And (root.SchemaClassName ="IIsWebServer") Then For i =0To root.Properties("ServerBindings").Count -1 If root.Properties("ServerBindings").Item(i) =":80:"&Trim(Me.TextBox1.Text) Then Me.Label1.Text ="主机头已经存在" root.Close() Exit Sub EndIf Next root.Properties("ServerBindings").Add(txtDomain) root.Invoke("SetInfo") EndIf Next root.Close() post1() End Sub PrivateFunction strPath()Function strPath(ByVal siteID AsString) AsObject Dim root As DirectoryEntry =New DirectoryEntry("IIS://localhost/W3SVC/"& siteID &"/ROOT") strPath = root.Properties("Path").Value root.Close() Return strPath End Function PrivateFunction strWebName()Function strWebName(ByVal webID AsString) AsObject Dim str1, str2 AsString Dim root As DirectoryEntry =New DirectoryEntry("IIS://localhost/W3SVC") ForEach root In root.Children If (root.Name = webID) And (root.SchemaClassName ="IIsWebServer") Then Dim t, i AsInteger For t =0To root.Properties("ServerBindings").Count -1 str2 &="主机头 "& t &" = "& root.Properties("ServerBindings").Item(t) &"<br>" Next str1 = root.Properties("ServerComment").Value EndIf Next Me.Label2.Text = str2 root.Close() Return str1 End Function PrivateSub post1()Sub post1() Dim intID AsInteger= Request("ID") Response.Write("网站名称= "& strWebName(intID)) Response.Write("<br>") Response.Write("所在路径= "& strPath(intID)) Response.Write("<p>") End Sub End Class