VB 自動(dòng)配置IIS
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
'建立活動(dòng)桌面'(IADS)對(duì)象,首先要引用 Active DS Type library 組件 Dim WWWServer As IADs, WWWService As IADs, WWWVDir, WWWVdirRes As IADs Function CreateWebSite(ByVal WWWSiteName As String, _ ByVal WWWSitePort As String, _ ByVal WWWSitePath As String, _ ByVal WWWHostName As String, _ ByVal ComputerName As String) As Boolean '變量定義 Dim SiteExist As Boolean Dim WebName '變量初始化 SiteExist = False WebName = 1 CreateWebSite = True On Error Resume Next Err.Clear '取得W3SVC服務(wù) Set WWWService = GetObject("IIS://" & ComputerName & "/W3SVC") Do While Err.Number <> 0 Err.Clear Set WWWService = GetObject("IIS://" & ComputerName & "/W3SVC") Loop Err.Clear '出錯(cuò)處理 '在IIS中查找每一個(gè)WEB站點(diǎn) For Each WWWServer In WWWService If UCase(Trim(WWWServer.ServerComment)) <> UCase(Trim(WWWSiteName)) Then If IsNumeric(WWWServer.Name) Then If CInt(WWWServer.Name) >= WebName Then WebName = CInt(WWWServer.Name) + 1 End If Else SiteExist = True Exit For End If Next If SiteExist Then MsgBox "該站點(diǎn)已經(jīng)存在!", vbInformation + vbOKOnly, "系統(tǒng)信息" Exit Function End If '創(chuàng)建WebServer Set WWWServer = WWWService.Create("IISWebServer", WebName) '創(chuàng)建新站點(diǎn) WWWServer.ServerComment = WWWSiteName '設(shè)置站點(diǎn)名 WWWServer.KeyType = "IISWebServer" WWWServer.ServerBindings = ":" & WWWSitePort & ":" & WWWHostName '設(shè)置端口號(hào)和主機(jī)頭 WWWServer.DefaultDoc = "Default.asp,Index.asp,Default.htm,Index.htm" '設(shè)置默認(rèn)啟動(dòng)文件 WWWServer.AccessScript = True '設(shè)置權(quán)限 WWWServer.AccessRead = True WWWServer.FrontPageWeb = True WWWServer.EnableDefaultDoc = True WWWServer.DefaultDoc = "Default.htm, Default.asp, Index.htm, Index.asp" Set WWWVDir = WWWServer.Create("IISWebVirtualDir", "Root") WWWVDir.Path = WWWSitePath WWWVDir.AppCreate True WWWVDir.SetInfo WWWServer.SetInfo WWWServer.Start MsgBox "主機(jī)設(shè)置成功!", vbInformation + vbOKOnly, "系統(tǒng)信息" 'Set WWWVdirRes = WWWVdir.Create("IISWebVirtualDir", "Resource") '創(chuàng)建虛擬目錄 'WWWVdirRes.Path = WWWFilesPath + "\Resource" 'WWWVdirRes.AccessRead = True 'WWWVdirRes.AccessWrite = True 'WWWVdirRes.SetInfo '下面為自定義IIS Web Server的錯(cuò)誤信息,等發(fā)生404錯(cuò)誤時(shí)候指定調(diào)用網(wǎng)站主目錄下的404.htm頁(yè)面顯示 'WWWServer.HttpErrors = "404,0,FILE," + WWWFilesPath + "\404.htm" 'WWWServer.SetInfo CreateWebSite = True End Function Function DeleteWebSite(ByVal WWWSiteName As String, ByVal ComputerName As String) As Boolean '定義變量 Dim Tmp As Integer Dim WebName Dim SiteExist As Boolean '變量初始化 SiteExist = False DeleteWebSite = True '取得W3SVC服務(wù) On Error Resume Next Err.Clear Set WWWService = GetObject("IIS://" & ComputerName & "/W3SVC") Do While Err.Number <> 0 Err.Clear Set WWWService = GetObject("IIS://" & ComputerName & "/W3SVC") Loop Err.Clear For Each WWWServer In WWWService If UCase(Trim(WWWServer.ServerComment)) <> UCase(Trim(WWWSiteName)) Then SiteExist = False Else If IsNumeric(WWWServer.Name) Then WebName = WWWServer.Name End If SiteExist = True Exit For End If Next '刪除站點(diǎn) WWWService.Delete "IISWebServer", WebName MsgBox "主機(jī)刪除成功!", vbInformation + vbOKOnly, "系統(tǒng)信息" End Function Private Sub cmdCreateWebSite_Click() CreateWebSite txtSiteName.Text, txtSitePort.Text, txtSitePath.Text, txtHostName.Text, txtComputerName.Text End Sub Private Sub cmdDeleteWebSite_Click() DeleteWebSite txtSiteName.Text, txtComputerName.Text End Sub 該文章在 2014/3/26 1:16:54 編輯過(guò)
|
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |