用ASP.NET(VB)创建的WEB站点,我们的调用方式非常简单: Dim test As New Class1() test.CreateWebSit(webname,port, "D:\VB", "localhost")
下面是Class1的代码,该代码做的工作就是建立站点,如果有此站点的名称则自动覆盖(注意:本类需要引用Actice DS Type Library) Public Class Class1
用localhost '===========================
Function CreateWebSit(ByVal WWWSiteName As String, _ ByVal WWWTCPPort As String, _ ByVal WWWFilesPath As String, _ ByVal ComputerName As String) As Boolean
CreateWebSit = True Dim TCPPort() As Object '建立活动桌面'(IADS)对象。首先要在 VB 中的 'prject'菜单中的'references'中引'用 Active DS 'Type 'library 组件 Dim WWWServer As ActiveDs.IADs Dim WWWService Dim WWWVdir, WWWVdir2, WWWVdirRes As ActiveDs.IADs Dim i As Integer Dim HandleSameCase As Boolean '取得W3SVC服务 WWWService = GetObject("IIS://" & ComputerName & "/W3SVC") i = 1 HandleSameCase = True On Error GoTo ErrWouldDo '在IIS中查找每一个WEB站点 For Each WWWServer In WWWService WWWServer = Nothing WWWServer = GetObject("IIS://" & ComputerName & "/W3SVC/" & i) 'Debug.Print WWWServer.ServerComment '如果在安装时系统中已经有了要加的站点,则要先删除干净 If UCase(WWWServer.ServerComment) = UCase(WWWSiteName) Then WWWService.Delete("IISWebServer", i) '再删除 Exit For End If ReDim TCPPort(1) TCPPort(0) = "" TCPPort = WWWServer.Serverbindings '如果端口已经有了则也要先删除 If TCPPort(0) = ":" & WWWTCPPort & ":" Then WWWService.Delete("IISWebServer", i) '删除 Else i = i + 1 End If Next HandleSameCase = False CreateSite: 'MsgBox I