Function CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop) Dim w3svc, WebServer, NewWebServer, NewDir Dim Bindings, BindingString, NewBindings, SiteNum, SiteObj, bDone On Error Resume Next Err.Clear '檢測是否能夠加載W3SVC服務(即WEB服務) Set w3svc = GetObject("IIS://" Computer "/w3svc") If Err.Number > 0 Then '顯示錯誤提示 response.write "無法打開: ""IIS://" Computer "/w3svc" response.end End If
'檢測是否有設定相同IP地址、端口及主機名的站點存在 BindingString = IPAddr ":" PortNum ":" HostName For Each WebServer in w3svc If WebServer.Class = "IIsWebServer" Then Bindings = WebServer.ServerBindings If BindingString = Bindings(0) Then response.write "IP地址沖突:" IPAddr ",請檢測IP地址!." Exit Function End If End If Next
Set NewDir = NewWebServer.Create("IIsWebVirtualDir", "ROOT") NewDir.Path = WebSiteDirectory NewDir.AccessRead = true NewDir.AppFriendlyName = "應用程序" WebSiteInfo NewDir.AppCreate True NewDir.AccessScript = True Err.Clear NewDir.SetInfo If (Err.Number = 0) Then Else response.write "主目錄創(chuàng)建時出錯." response.end End If
If StartOrStop = True Then Err.Clear Set NewWebServer = GetObject("IIS://" Computer "/w3svc/" SiteNum) NewWebServer.Start If Err.Number > 0 Then response.write "啟動站點時出錯!" response.end Err.Clear Else End If End If response.write "站點創(chuàng)建成功,站點編號為:" SiteNum " ,域名為:" HostName End Function