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 "主目录创建时出错." 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 "站点创建成功,站点编号为:" SiteNum " ,域名为:" HostName End Function